<!DOCTYPE html>
<html lang="zh-CN">
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <meta name="robots" content="noodp" />
        <title>大数加减类的实现(C&#43;&#43;实现)✨ - L_B__</title><meta name="referrer" content="no-referrer">
<meta name="description" content="”简单学习下基本的类封装“"><meta property="og:title" content="大数加减类的实现(C&#43;&#43;实现)✨" />
<meta property="og:description" content="”简单学习下基本的类封装“" />
<meta property="og:type" content="article" />
<meta property="og:url" content="https://acking-you.github.io/posts/%E5%A4%A7%E6%95%B4%E6%95%B0%E5%8A%A0%E5%87%8F/" /><meta property="og:image" content="https://acking-you.github.io/logo.png"/><meta property="article:section" content="posts" />
<meta property="article:published_time" content="2022-01-20T00:00:00+00:00" />
<meta property="article:modified_time" content="2022-01-20T00:00:00+00:00" />

<meta name="twitter:card" content="summary_large_image"/>
<meta name="twitter:image" content="https://acking-you.github.io/logo.png"/>

<meta name="twitter:title" content="大数加减类的实现(C&#43;&#43;实现)✨"/>
<meta name="twitter:description" content="”简单学习下基本的类封装“"/>
<meta name="application-name" content="FeelIt">
<meta name="apple-mobile-web-app-title" content="FeelIt"><meta name="theme-color" content="#ffffff"><meta name="msapplication-TileColor" content="#da532c"><link rel="canonical" href="https://acking-you.github.io/posts/%E5%A4%A7%E6%95%B4%E6%95%B0%E5%8A%A0%E5%87%8F/" /><link rel="prev" href="https://acking-you.github.io/posts/%E7%9F%A9%E9%98%B5%E5%BF%AB%E9%80%9F%E5%B9%82%E7%9A%84c&#43;&#43;%E5%B0%81%E8%A3%85/" /><link rel="next" href="https://acking-you.github.io/posts/socket%E5%9F%BA%E6%9C%AC%E6%93%8D%E4%BD%9Cc&#43;&#43;%E5%B0%81%E8%A3%85/" /><link rel="stylesheet" href="/css/page.min.css"><link rel="stylesheet" href="/css/home.min.css"><script type="application/ld+json">
    {
        "@context": "http://schema.org",
        "@type": "BlogPosting",
        "headline": "大数加减类的实现(C++实现)✨",
        "inLanguage": "zh-CN",
        "mainEntityOfPage": {
            "@type": "WebPage",
            "@id": "https:\/\/acking-you.github.io\/posts\/%E5%A4%A7%E6%95%B4%E6%95%B0%E5%8A%A0%E5%87%8F\/"
        },"genre": "posts","keywords": "C\u002b\u002b类的封装","wordcount":  5922 ,
        "url": "https:\/\/acking-you.github.io\/posts\/%E5%A4%A7%E6%95%B4%E6%95%B0%E5%8A%A0%E5%87%8F\/","datePublished": "2022-01-20T00:00:00+00:00","dateModified": "2022-01-20T00:00:00+00:00","publisher": {
            "@type": "Organization",
            "name": "作者"},"author": {
                "@type": "Person",
                "name": "作者"
            },"description": "”简单学习下基本的类封装“"
    }
    </script></head><body data-header-desktop="auto" data-header-mobile="auto"><script>(window.localStorage && localStorage.getItem('theme') ? localStorage.getItem('theme') === 'dark' : ('auto' === 'auto' ? window.matchMedia('(prefers-color-scheme: dark)').matches : 'auto' === 'dark')) && document.body.setAttribute('theme', 'dark');</script>

        <div id="mask"></div><div class="wrapper"><header class="desktop" id="header-desktop">
    <div class="header-wrapper">
        <div class="header-title">
            <a href="/" title="L_B__">L_B__</a>
        </div>
        <div class="menu">
            <div class="menu-inner"><a class="menu-item" href="/posts/"> 文章 </a><a class="menu-item" href="/tags/"> 标签 </a><a class="menu-item" href="/categories/"> 分类 </a><span class="menu-item delimiter"></span><span class="menu-item search" id="search-desktop">
                        <input type="text" placeholder="搜索文章标题或内容..." id="search-input-desktop">
                        <a href="#" class="search-button search-toggle" id="search-toggle-desktop" title="搜索">
                            <i class="fas fa-search fa-fw"></i>
                        </a>
                        <a href="#" class="search-button search-clear" id="search-clear-desktop" title="清空">
                            <i class="fas fa-times-circle fa-fw"></i>
                        </a>
                        <span class="search-button search-loading" id="search-loading-desktop">
                            <i class="fas fa-spinner fa-fw fa-spin"></i>
                        </span>
                    </span><a href="javascript:void(0);" class="menu-item theme-switch" title="切换主题">
                    <i class="fas fa-adjust fa-fw"></i>
                </a>
            </div>
        </div>
    </div>
</header><header class="mobile" id="header-mobile">
    <div class="header-container">
        <div class="header-wrapper">
            <div class="header-title">
                <a href="/" title="L_B__">L_B__</a>
            </div>
            <div class="menu-toggle" id="menu-toggle-mobile">
                <span></span><span></span><span></span>
            </div>
        </div>
        <div class="menu" id="menu-mobile"><div class="search-wrapper">
                    <div class="search mobile" id="search-mobile">
                        <input type="text" placeholder="搜索文章标题或内容..." id="search-input-mobile">
                        <a href="#" class="search-button search-toggle" id="search-toggle-mobile" title="搜索">
                            <i class="fas fa-search fa-fw"></i>
                        </a>
                        <a href="#" class="search-button search-clear" id="search-clear-mobile" title="清空">
                            <i class="fas fa-times-circle fa-fw"></i>
                        </a>
                        <span class="search-button search-loading" id="search-loading-mobile">
                            <i class="fas fa-spinner fa-fw fa-spin"></i>
                        </span>
                    </div>
                    <a href="#" class="search-cancel" id="search-cancel-mobile">
                        取消
                    </a>
                </div><a class="menu-item" href="/posts/" title="">文章</a><a class="menu-item" href="/tags/" title="">标签</a><a class="menu-item" href="/categories/" title="">分类</a><div class="menu-item"><a href="javascript:void(0);" class="theme-switch" title="切换主题">
                    <i class="fas fa-adjust fa-fw"></i>
                </a>
            </div></div>
    </div>
</header><div class="search-dropdown desktop">
    <div id="search-dropdown-desktop"></div>
</div>
<div class="search-dropdown mobile">
    <div id="search-dropdown-mobile"></div>
</div><main class="main">
                <div class="container"><div class="toc" id="toc-auto">
            <h2 class="toc-title">目录</h2>
            <div class="toc-content" id="toc-content-auto"></div>
        </div><article class="page single" data-toc="disable"><div class="featured-image"><img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://img-blog.csdnimg.cn/d01d5f8864d540fd9f68582d8f01d017.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBAQ19ZQ0JYIFB5X1lZRFM=,size_20,color_FFFFFF,t_70,g_se,x_16"
        data-srcset="https://img-blog.csdnimg.cn/d01d5f8864d540fd9f68582d8f01d017.png?x-oss-process=image/watermark%2ctype_ZHJvaWRzYW5zZmFsbGJhY2s%2cshadow_50%2ctext_Q1NETiBAQ19ZQ0JYIFB5X1lZRFM=%2csize_20%2ccolor_FFFFFF%2ct_70%2cg_se%2cx_16, https://img-blog.csdnimg.cn/d01d5f8864d540fd9f68582d8f01d017.png?x-oss-process=image/watermark%2ctype_ZHJvaWRzYW5zZmFsbGJhY2s%2cshadow_50%2ctext_Q1NETiBAQ19ZQ0JYIFB5X1lZRFM=%2csize_20%2ccolor_FFFFFF%2ct_70%2cg_se%2cx_16 1.5x, https://img-blog.csdnimg.cn/d01d5f8864d540fd9f68582d8f01d017.png?x-oss-process=image/watermark%2ctype_ZHJvaWRzYW5zZmFsbGJhY2s%2cshadow_50%2ctext_Q1NETiBAQ19ZQ0JYIFB5X1lZRFM=%2csize_20%2ccolor_FFFFFF%2ct_70%2cg_se%2cx_16 2x"
        data-sizes="auto"
        alt="https://img-blog.csdnimg.cn/d01d5f8864d540fd9f68582d8f01d017.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBAQ19ZQ0JYIFB5X1lZRFM=,size_20,color_FFFFFF,t_70,g_se,x_16"
        title="”简单学习下基本的类封装“" /></div><div class="single-card" data-image="true"><h2 class="single-title animated flipInX">大数加减类的实现(C&#43;&#43;实现)✨</h2><div class="post-meta">
                <div class="post-meta-line"><span class="post-author"><a href="/" title="Author" rel=" author" class="author"><i class="fas fa-user-circle fa-fw"></i>作者</a></span>&nbsp;<span class="post-category">出版于  <a href="/categories/c++%E5%AE%9E%E6%88%98/"><i class="far fa-folder fa-fw"></i>C++实战</a></span></div>
                <div class="post-meta-line"><span><i class="far fa-calendar-alt fa-fw"></i>&nbsp;<time datetime="2022-01-20">2022-01-20</time></span>&nbsp;<span><i class="fas fa-pencil-alt fa-fw"></i>&nbsp;约 5922 字</span>&nbsp;
                    <span><i class="far fa-clock fa-fw"></i>&nbsp;预计阅读 12 分钟</span>&nbsp;</div>
            </div>
            
            <hr><div class="details toc" id="toc-static"  data-kept="">
                    <div class="details-summary toc-title">
                        <span>目录</span>
                        <span><i class="details-icon fas fa-angle-right"></i></span>
                    </div>
                    <div class="details-content toc-content" id="toc-content-static"><nav id="TableOfContents">
  <ul>
    <li><a href="#为什么需要大数加减类">为什么需要大数加减类？</a></li>
    <li><a href="#大数加减类实现详解">大数加减类实现详解</a>
      <ul>
        <li><a href="#一流程图总览">一、流程图总览</a></li>
        <li><a href="#二成员数据和构造函数详解">二、成员数据和构造函数详解</a></li>
        <li><a href="#三算法核心静态成员函数和运算符重载详解">三、(算法核心)静态成员函数和运算符重载详解</a></li>
        <li><a href="#四其他内部成员函数详解">四、其他内部成员函数详解</a></li>
      </ul>
    </li>
    <li><a href="#整理代码">整理代码</a>
      <ul>
        <li><a href="#h声明文件">.h声明文件</a></li>
        <li><a href="#cpp定义并实现">.cpp定义并实现</a></li>
      </ul>
    </li>
    <li><a href="#功能测试">功能测试</a>
      <ul>
        <li><a href="#一基本的加减测试">一、基本的加减测试</a></li>
        <li><a href="#二存储个人输入的数据排序测试">二、存储个人输入的数据+排序测试</a></li>
        <li><a href="#三解题测试">三、解题测试</a></li>
      </ul>
    </li>
    <li><a href="#总结">总结</a></li>
  </ul>
</nav></div>
                </div><div class="content" id="content"><h2 id="为什么需要大数加减类">为什么需要大数加减类？</h2>
<blockquote>
<p>对于计算机而言，基本的数据类型一般最多为64位数据表示范围，这个范围是有限的，没法无限的表示所有的数据，那么有没有一种方式能够表示所有的大数，并完成加减乘除呢？</p>
</blockquote>
<p>答案肯定是有的，由于数据都是由一位一位的数字所组成，我们只需要用数组中的每一位表示一位数字，便可完成对大数的模拟了。</p>
<p>那么我们说明时候需要用到大数模拟呢？<strong>对竞赛人而言，有很多题目实际上就是高精度大数模拟类型，而对于普通的程序员而言，大数模拟也仅是在做某个逻辑运算而保证不会溢出的最佳策略</strong>，那么大家难道不好奇如何实现一个大数模拟类吗？</p>
<p>现在就从封装一个简单的加减类开始了解这样一个大数模拟是怎么实现的👀</p>
<h2 id="大数加减类实现详解">大数加减类实现详解</h2>
<h3 id="一流程图总览">一、流程图总览</h3>
<p><img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://img-blog.csdnimg.cn/f2558355698b42b391e5faffa6880aac.jpg?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBAQ19ZQ0JYIFB5X1lZRFM=,size_20,color_FFFFFF,t_70,g_se,x_16"
        data-srcset="https://img-blog.csdnimg.cn/f2558355698b42b391e5faffa6880aac.jpg?x-oss-process=image/watermark%2ctype_ZHJvaWRzYW5zZmFsbGJhY2s%2cshadow_50%2ctext_Q1NETiBAQ19ZQ0JYIFB5X1lZRFM=%2csize_20%2ccolor_FFFFFF%2ct_70%2cg_se%2cx_16, https://img-blog.csdnimg.cn/f2558355698b42b391e5faffa6880aac.jpg?x-oss-process=image/watermark%2ctype_ZHJvaWRzYW5zZmFsbGJhY2s%2cshadow_50%2ctext_Q1NETiBAQ19ZQ0JYIFB5X1lZRFM=%2csize_20%2ccolor_FFFFFF%2ct_70%2cg_se%2cx_16 1.5x, https://img-blog.csdnimg.cn/f2558355698b42b391e5faffa6880aac.jpg?x-oss-process=image/watermark%2ctype_ZHJvaWRzYW5zZmFsbGJhY2s%2cshadow_50%2ctext_Q1NETiBAQ19ZQ0JYIFB5X1lZRFM=%2csize_20%2ccolor_FFFFFF%2ct_70%2cg_se%2cx_16 2x"
        data-sizes="auto"
        alt="https://img-blog.csdnimg.cn/f2558355698b42b391e5faffa6880aac.jpg?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBAQ19ZQ0JYIFB5X1lZRFM=,size_20,color_FFFFFF,t_70,g_se,x_16"
        title="https://img-blog.csdnimg.cn/f2558355698b42b391e5faffa6880aac.jpg?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBAQ19ZQ0JYIFB5X1lZRFM=,size_20,color_FFFFFF,t_70,g_se,x_16" /></p>
<ul>
<li>如图总体来说分为五部分：</li>
</ul>
<ol>
<li>静态成员函数：属于类的公共接口(核心)</li>
<li>构造和析构函数：构造对象以及析构对象</li>
<li>成员数据：用于运算的数据以及表示对象的数据</li>
<li>运算符重载：用于自定义运算方式(核心)</li>
<li>内部成员函数：属于对象的公共接口</li>
</ol>
<h3 id="二成员数据和构造函数详解">二、成员数据和构造函数详解</h3>
<ol>
<li><strong>成员数据</strong></li>
</ol>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-cpp" data-lang="cpp">    <span class="kt">bool</span> <span class="n">f</span><span class="p">;</span>			<span class="c1">//是否是负数的标记
</span><span class="c1"></span>    <span class="kt">char</span> <span class="o">*</span><span class="n">nums</span><span class="p">;</span>		<span class="c1">//存储非符号的大数各个位
</span><span class="c1"></span>    <span class="kt">int</span> <span class="n">length</span><span class="p">;</span>		<span class="c1">//nums的数据长度
</span><span class="c1"></span>    <span class="kt">int</span> <span class="n">capacity</span><span class="p">;</span>	<span class="c1">//nums的可用容量
</span></code></pre></div><ol start="2">
<li><strong>构造和析构</strong></li>
</ol>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-cpp" data-lang="cpp"><span class="c1">//缺省构造函数
</span><span class="c1"></span><span class="n">BigInteger</span><span class="p">()</span> <span class="o">:</span> <span class="n">length</span><span class="p">(</span><span class="mi">0</span><span class="p">),</span> <span class="n">capacity</span><span class="p">(</span><span class="mi">1</span><span class="p">),</span> <span class="n">f</span><span class="p">(</span><span class="nb">false</span><span class="p">)</span> <span class="p">{</span> 
        <span class="n">nums</span> <span class="o">=</span> <span class="k">new</span> <span class="kt">char</span><span class="p">[</span><span class="n">capacity</span><span class="p">];</span>
    <span class="p">}</span>
<span class="c1">//用于转化普通字符串的构造函数
</span><span class="c1"></span><span class="n">BigInteger</span><span class="p">(</span><span class="k">const</span> <span class="kt">char</span> <span class="o">*</span><span class="n">n</span><span class="p">)</span> <span class="o">:</span> <span class="n">length</span><span class="p">(</span><span class="n">strlen</span><span class="p">(</span><span class="n">n</span><span class="p">)),</span> <span class="n">f</span><span class="p">(</span><span class="nb">false</span><span class="p">)</span> <span class="p">{</span> 
        <span class="kt">int</span> <span class="n">start</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
        <span class="k">if</span> <span class="p">(</span><span class="n">n</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">==</span> <span class="sc">&#39;-&#39;</span><span class="p">)</span> <span class="p">{</span>
            <span class="n">f</span> <span class="o">=</span> <span class="nb">true</span><span class="p">;</span>
            <span class="n">start</span><span class="o">++</span><span class="p">;</span>
        <span class="p">}</span>
        <span class="k">while</span> <span class="p">(</span><span class="n">start</span><span class="o">&lt;</span><span class="n">length</span><span class="o">&amp;&amp;</span><span class="n">n</span><span class="p">[</span><span class="n">start</span><span class="p">]</span> <span class="o">==</span> <span class="sc">&#39;0&#39;</span><span class="p">)</span><span class="n">start</span><span class="o">++</span><span class="p">;</span>
        <span class="n">capacity</span> <span class="o">=</span> <span class="n">length</span> <span class="o">*</span> <span class="mi">10</span><span class="p">;</span>
        <span class="n">nums</span> <span class="o">=</span> <span class="k">new</span> <span class="kt">char</span><span class="p">[</span><span class="n">capacity</span><span class="p">];</span>
        <span class="n">std</span><span class="o">::</span><span class="n">copy</span><span class="p">(</span><span class="n">n</span> <span class="o">+</span> <span class="n">start</span><span class="p">,</span> <span class="n">n</span> <span class="o">+</span> <span class="n">length</span><span class="p">,</span> <span class="n">nums</span><span class="p">);</span>
        <span class="n">length</span> <span class="o">=</span> <span class="n">length</span> <span class="o">-</span> <span class="n">start</span><span class="p">;</span>
<span class="p">}</span>
<span class="c1">//拷贝构造函数
</span><span class="c1"></span><span class="n">BigInteger</span><span class="p">(</span><span class="n">BigInteger</span> <span class="o">&amp;</span><span class="n">a</span><span class="p">)</span> <span class="p">{</span>  
        <span class="n">capacity</span> <span class="o">=</span> <span class="n">a</span><span class="p">.</span><span class="n">capacity</span><span class="p">;</span>
        <span class="n">length</span> <span class="o">=</span> <span class="n">a</span><span class="p">.</span><span class="n">length</span><span class="p">;</span>
        <span class="n">f</span> <span class="o">=</span> <span class="n">a</span><span class="p">.</span><span class="n">f</span><span class="p">;</span>
        <span class="n">nums</span> <span class="o">=</span> <span class="k">new</span> <span class="kt">char</span><span class="p">[</span><span class="n">capacity</span><span class="p">];</span>
        <span class="n">std</span><span class="o">::</span><span class="n">copy</span><span class="p">(</span><span class="n">a</span><span class="p">.</span><span class="n">nums</span><span class="p">,</span> <span class="n">a</span><span class="p">.</span><span class="n">nums</span> <span class="o">+</span> <span class="n">length</span><span class="p">,</span> <span class="n">nums</span><span class="p">);</span>
<span class="p">}</span>
<span class="c1">//移动构造函数：这里调用了等于号，根据a的类型来决定用哪个等于号
</span><span class="c1"></span><span class="n">BigInteger</span><span class="p">(</span><span class="n">BigInteger</span> <span class="o">&amp;&amp;</span><span class="n">a</span><span class="p">)</span> <span class="o">:</span><span class="n">length</span><span class="p">(</span><span class="mi">0</span><span class="p">){</span>
        <span class="o">*</span><span class="k">this</span> <span class="o">=</span> <span class="n">a</span><span class="p">;</span>
<span class="p">}</span>
<span class="c1">//析构函数
</span><span class="c1"></span><span class="o">~</span><span class="n">BigInteger</span><span class="p">()</span> <span class="p">{</span> 
        <span class="k">delete</span><span class="p">[]</span> <span class="n">nums</span><span class="p">;</span>
<span class="p">}</span>
</code></pre></div><h3 id="三算法核心静态成员函数和运算符重载详解">三、(算法核心)静态成员函数和运算符重载详解</h3>
<h4 id="static-swap">static Swap()</h4>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-cpp" data-lang="cpp"><span class="c1">//调用std的swap实现对基本数据的交换
</span><span class="c1"></span><span class="k">static</span> <span class="kt">void</span> <span class="nf">Swap</span><span class="p">(</span><span class="n">BigInteger</span> <span class="o">&amp;</span><span class="n">a</span><span class="p">,</span> <span class="n">BigInteger</span> <span class="o">&amp;</span><span class="n">b</span><span class="p">)</span> <span class="p">{</span>
        <span class="n">std</span><span class="o">::</span><span class="n">swap</span><span class="p">(</span><span class="n">a</span><span class="p">.</span><span class="n">length</span><span class="p">,</span> <span class="n">b</span><span class="p">.</span><span class="n">length</span><span class="p">);</span>
        <span class="n">std</span><span class="o">::</span><span class="n">swap</span><span class="p">(</span><span class="n">a</span><span class="p">.</span><span class="n">capacity</span><span class="p">,</span> <span class="n">b</span><span class="p">.</span><span class="n">capacity</span><span class="p">);</span>
        <span class="n">std</span><span class="o">::</span><span class="n">swap</span><span class="p">(</span><span class="n">a</span><span class="p">.</span><span class="n">f</span><span class="p">,</span> <span class="n">b</span><span class="p">.</span><span class="n">f</span><span class="p">);</span>
        <span class="n">std</span><span class="o">::</span><span class="n">swap</span><span class="p">(</span><span class="n">a</span><span class="p">.</span><span class="n">nums</span><span class="p">,</span> <span class="n">b</span><span class="p">.</span><span class="n">nums</span><span class="p">);</span>
<span class="p">}</span>
</code></pre></div><h4 id="static-compare">static compare()</h4>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-cpp" data-lang="cpp"><span class="c1">//不看符号比较nums的大小：表示a是否比b大
</span><span class="c1"></span><span class="k">static</span> <span class="kt">bool</span> <span class="nf">compare</span><span class="p">(</span><span class="k">const</span> <span class="n">BigInteger</span> <span class="o">&amp;</span><span class="n">a</span><span class="p">,</span><span class="k">const</span> <span class="n">BigInteger</span> <span class="o">&amp;</span><span class="n">b</span><span class="p">)</span> <span class="p">{</span> <span class="c1">//比较纯nums大小(不看符号
</span><span class="c1"></span>        <span class="kt">int</span> <span class="n">n1</span> <span class="o">=</span> <span class="n">a</span><span class="p">.</span><span class="n">length</span><span class="p">;</span>
        <span class="kt">int</span> <span class="n">n2</span> <span class="o">=</span> <span class="n">b</span><span class="p">.</span><span class="n">length</span><span class="p">;</span>
        <span class="k">if</span> <span class="p">(</span><span class="n">n1</span> <span class="o">!=</span> <span class="n">n2</span><span class="p">)</span><span class="k">return</span> <span class="n">n1</span> <span class="o">&gt;</span> <span class="n">n2</span><span class="p">;</span> <span class="c1">//返回a和b哪个大，true则位a大
</span><span class="c1"></span>        <span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
        <span class="k">while</span> <span class="p">(</span><span class="n">i</span> <span class="o">&lt;</span> <span class="n">n1</span> <span class="o">&amp;&amp;</span> <span class="n">a</span><span class="p">.</span><span class="n">nums</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">==</span> <span class="n">b</span><span class="p">.</span><span class="n">nums</span><span class="p">[</span><span class="n">i</span><span class="p">])</span><span class="n">i</span><span class="o">++</span><span class="p">;</span> <span class="c1">//a b一样长的情况下，比较两个的值
</span><span class="c1"></span>        <span class="k">if</span> <span class="p">(</span><span class="n">i</span> <span class="o">==</span> <span class="n">n1</span><span class="p">)</span>
            <span class="k">return</span> <span class="nb">false</span><span class="p">;</span>
        <span class="k">return</span> <span class="n">a</span><span class="p">.</span><span class="n">nums</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">&gt;</span> <span class="n">b</span><span class="p">.</span><span class="n">nums</span><span class="p">[</span><span class="n">i</span><span class="p">];</span>
<span class="p">}</span>
</code></pre></div><h4 id="static-isequal">static isEqual()</h4>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-cpp" data-lang="cpp"><span class="c1">//表示a和b是否相等
</span><span class="c1"></span><span class="kt">bool</span> <span class="nf">isEqual</span><span class="p">(</span><span class="n">BigInteger</span> <span class="o">&amp;</span><span class="n">a</span><span class="p">,</span> <span class="n">BigInteger</span> <span class="o">&amp;</span><span class="n">b</span><span class="p">)</span> <span class="p">{</span>
        <span class="k">if</span> <span class="p">(</span><span class="n">a</span><span class="p">.</span><span class="n">f</span> <span class="o">!=</span> <span class="n">b</span><span class="p">.</span><span class="n">f</span> <span class="o">||</span> <span class="p">(</span><span class="n">a</span><span class="p">.</span><span class="n">length</span> <span class="o">!=</span> <span class="n">b</span><span class="p">.</span><span class="n">length</span><span class="p">))</span><span class="k">return</span> <span class="nb">false</span><span class="p">;</span>
        <span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
        <span class="k">while</span> <span class="p">(</span><span class="n">i</span> <span class="o">&lt;</span> <span class="n">a</span><span class="p">.</span><span class="n">length</span> <span class="o">&amp;&amp;</span> <span class="n">a</span><span class="p">.</span><span class="n">nums</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">==</span> <span class="n">b</span><span class="p">.</span><span class="n">nums</span><span class="p">[</span><span class="n">i</span><span class="p">])</span><span class="n">i</span><span class="o">++</span><span class="p">;</span>
        <span class="k">return</span> <span class="n">i</span> <span class="o">==</span> <span class="n">a</span><span class="p">.</span><span class="n">length</span> <span class="o">&amp;&amp;</span> <span class="n">a</span><span class="p">.</span><span class="n">f</span> <span class="o">==</span> <span class="n">b</span><span class="p">.</span><span class="n">f</span><span class="p">;</span>
<span class="p">}</span>
</code></pre></div><h4 id="核心算法static-add">(*核心算法)static add()</h4>
<blockquote>
<p>不看符号的加法，符号这方面由重载加法运算符控制。</p>
</blockquote>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-cpp" data-lang="cpp"><span class="k">static</span> <span class="n">BigInteger</span> <span class="nf">add</span><span class="p">(</span><span class="n">BigInteger</span> <span class="o">&amp;</span><span class="n">a</span><span class="p">,</span> <span class="n">BigInteger</span> <span class="o">&amp;</span><span class="n">b</span><span class="p">)</span> <span class="p">{</span> <span class="c1">//不看符号的加法
</span><span class="c1"></span>    <span class="n">a</span><span class="p">.</span><span class="n">reverse</span><span class="p">();</span><span class="c1">//尾端对齐
</span><span class="c1"></span>    <span class="n">b</span><span class="p">.</span><span class="n">reverse</span><span class="p">();</span>
    <span class="n">BigInteger</span> <span class="n">t</span><span class="p">;</span>
    <span class="kt">int</span> <span class="n">up</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
    <span class="kt">int</span> <span class="n">len</span> <span class="o">=</span> <span class="n">a</span><span class="p">.</span><span class="n">length</span> <span class="o">&gt;</span> <span class="n">b</span><span class="p">.</span><span class="n">length</span> <span class="o">?</span> <span class="n">a</span><span class="p">.</span><span class="nl">length</span> <span class="p">:</span> <span class="n">b</span><span class="p">.</span><span class="n">length</span><span class="p">;</span>
    <span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o">&lt;</span> <span class="n">len</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span> <span class="p">{</span>
        <span class="kt">int</span> <span class="n">ta</span> <span class="o">=</span> <span class="n">i</span> <span class="o">&lt;</span> <span class="n">a</span><span class="p">.</span><span class="n">length</span> <span class="o">?</span> <span class="n">a</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">-</span> <span class="sc">&#39;0&#39;</span> <span class="o">:</span> <span class="mi">0</span><span class="p">;</span>
        <span class="kt">int</span> <span class="n">tb</span> <span class="o">=</span> <span class="n">i</span> <span class="o">&lt;</span> <span class="n">b</span><span class="p">.</span><span class="n">length</span> <span class="o">?</span> <span class="n">b</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">-</span> <span class="sc">&#39;0&#39;</span> <span class="o">:</span> <span class="mi">0</span><span class="p">;</span>
        <span class="kt">int</span> <span class="n">base</span> <span class="o">=</span> <span class="n">ta</span> <span class="o">+</span> <span class="n">tb</span> <span class="o">+</span> <span class="n">up</span><span class="p">;</span>
        <span class="n">t</span><span class="p">.</span><span class="n">push_back</span><span class="p">(</span><span class="n">base</span> <span class="o">%</span> <span class="mi">10</span> <span class="o">+</span> <span class="sc">&#39;0&#39;</span><span class="p">);</span>
        <span class="n">up</span> <span class="o">=</span> <span class="n">base</span> <span class="o">/</span> <span class="mi">10</span><span class="p">;</span>
    <span class="p">}</span>
    <span class="k">if</span> <span class="p">(</span><span class="n">up</span><span class="p">)</span>
        <span class="n">t</span><span class="p">.</span><span class="n">push_back</span><span class="p">(</span><span class="n">up</span> <span class="o">+</span> <span class="sc">&#39;0&#39;</span><span class="p">);</span>
    <span class="n">t</span><span class="p">.</span><span class="n">reverse</span><span class="p">();</span><span class="c1">//返回原位
</span><span class="c1"></span>    <span class="n">a</span><span class="p">.</span><span class="n">reverse</span><span class="p">();</span>
    <span class="n">b</span><span class="p">.</span><span class="n">reverse</span><span class="p">();</span>
    <span class="k">return</span> <span class="n">t</span><span class="p">;</span>
<span class="p">}</span>
</code></pre></div><h4 id="核心算法static-minus">(*核心算法)static minus()</h4>
<blockquote>
<p>不看符号的减法,默认了a的nums大小(不看符号)是比b大的。</p>
</blockquote>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-cpp" data-lang="cpp"><span class="k">static</span> <span class="n">BigInteger</span> <span class="nf">minus</span><span class="p">(</span><span class="n">BigInteger</span> <span class="o">&amp;</span><span class="n">a</span><span class="p">,</span> <span class="n">BigInteger</span> <span class="o">&amp;</span><span class="n">b</span><span class="p">)</span> <span class="p">{</span>
    <span class="n">a</span><span class="p">.</span><span class="n">reverse</span><span class="p">();</span>
    <span class="n">b</span><span class="p">.</span><span class="n">reverse</span><span class="p">();</span>
    <span class="n">BigInteger</span> <span class="n">t</span><span class="p">;</span>
    <span class="kt">int</span> <span class="n">len</span> <span class="o">=</span> <span class="n">a</span><span class="p">.</span><span class="n">length</span> <span class="o">&gt;</span> <span class="n">b</span><span class="p">.</span><span class="n">length</span> <span class="o">?</span> <span class="n">a</span><span class="p">.</span><span class="nl">length</span> <span class="p">:</span> <span class="n">b</span><span class="p">.</span><span class="n">length</span><span class="p">;</span>
    <span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o">&lt;</span> <span class="n">len</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span> <span class="p">{</span>
        <span class="kt">int</span> <span class="n">ta</span> <span class="o">=</span> <span class="n">i</span> <span class="o">&lt;</span> <span class="n">a</span><span class="p">.</span><span class="n">length</span> <span class="o">?</span> <span class="n">a</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">-</span> <span class="sc">&#39;0&#39;</span> <span class="o">:</span> <span class="mi">0</span><span class="p">;</span>
        <span class="kt">int</span> <span class="n">tb</span> <span class="o">=</span> <span class="n">i</span> <span class="o">&lt;</span> <span class="n">b</span><span class="p">.</span><span class="n">length</span> <span class="o">?</span> <span class="n">b</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">-</span> <span class="sc">&#39;0&#39;</span> <span class="o">:</span> <span class="mi">0</span><span class="p">;</span>
        <span class="kt">int</span> <span class="n">base</span> <span class="o">=</span> <span class="n">ta</span> <span class="o">-</span> <span class="n">tb</span><span class="p">;</span>
        <span class="k">if</span> <span class="p">(</span><span class="n">base</span> <span class="o">&lt;</span> <span class="mi">0</span><span class="p">)</span> <span class="p">{</span>
            <span class="n">base</span> <span class="o">+=</span> <span class="mi">10</span><span class="p">;</span>
            <span class="n">a</span><span class="p">[</span><span class="n">i</span> <span class="o">+</span> <span class="mi">1</span><span class="p">]</span><span class="o">--</span><span class="p">;</span>
        <span class="p">}</span>
        <span class="n">t</span><span class="p">.</span><span class="n">push_back</span><span class="p">(</span><span class="n">base</span> <span class="o">+</span> <span class="sc">&#39;0&#39;</span><span class="p">);</span>
    <span class="p">}</span>
    <span class="n">t</span><span class="p">.</span><span class="n">reverse</span><span class="p">();</span>
    <span class="n">a</span><span class="p">.</span><span class="n">reverse</span><span class="p">();</span>
    <span class="n">b</span><span class="p">.</span><span class="n">reverse</span><span class="p">();</span>
    <span class="k">return</span> <span class="n">t</span><span class="p">;</span>
<span class="p">}</span>
</code></pre></div><h4 id="char-operator">char &amp;operator[]</h4>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-cpp" data-lang="cpp"><span class="kt">char</span> <span class="o">&amp;</span><span class="k">operator</span><span class="p">[](</span><span class="kt">int</span> <span class="n">i</span><span class="p">)</span> <span class="p">{</span>
        <span class="k">return</span> <span class="n">nums</span><span class="p">[</span><span class="n">i</span><span class="p">];</span>
<span class="p">}</span>
</code></pre></div><h4 id="biginteger-operator">BigInteger &amp;operator=</h4>
<blockquote>
<p>用了两个版本&ndash;右值引用和左值引用版本</p>
</blockquote>
<ul>
<li>右值引用延长寿命，用交换的方式实现(毕竟是将亡值</li>
</ul>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-cpp" data-lang="cpp"><span class="n">BigInteger</span> <span class="o">&amp;</span><span class="k">operator</span><span class="o">=</span><span class="p">(</span><span class="n">BigInteger</span><span class="o">&amp;&amp;</span> <span class="n">a</span><span class="p">)</span> <span class="p">{</span> <span class="c1">//Swap&amp;Copy方式实现右值赋值重载
</span><span class="c1"></span>    <span class="n">Swap</span><span class="p">(</span><span class="o">*</span><span class="k">this</span><span class="p">,</span> <span class="n">a</span><span class="p">);</span>
    <span class="k">return</span> <span class="o">*</span><span class="k">this</span><span class="p">;</span>
<span class="p">}</span>
</code></pre></div><ul>
<li>左值引用深拷贝</li>
</ul>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-cpp" data-lang="cpp"><span class="n">BigInteger</span> <span class="o">&amp;</span><span class="k">operator</span><span class="o">=</span><span class="p">(</span><span class="k">const</span> <span class="n">BigInteger</span> <span class="o">&amp;</span><span class="n">a</span><span class="p">)</span> <span class="p">{</span><span class="c1">//深拷贝
</span><span class="c1"></span>        <span class="k">if</span> <span class="p">(</span><span class="n">length</span> <span class="o">!=</span> <span class="mi">0</span><span class="p">)</span><span class="c1">//如果不是初始化调用的 = ，则肯定需要先把原来的内存delete掉
</span><span class="c1"></span>            <span class="k">delete</span><span class="p">[]</span><span class="n">nums</span><span class="p">;</span>
        <span class="n">capacity</span> <span class="o">=</span> <span class="n">a</span><span class="p">.</span><span class="n">capacity</span><span class="p">;</span>
        <span class="n">length</span> <span class="o">=</span> <span class="n">a</span><span class="p">.</span><span class="n">length</span><span class="p">;</span>
        <span class="n">f</span> <span class="o">=</span> <span class="n">a</span><span class="p">.</span><span class="n">f</span><span class="p">;</span>
        <span class="n">nums</span> <span class="o">=</span> <span class="k">new</span> <span class="kt">char</span><span class="p">[</span><span class="n">capacity</span><span class="p">];</span>
        <span class="n">std</span><span class="o">::</span><span class="n">copy</span><span class="p">(</span><span class="n">a</span><span class="p">.</span><span class="n">nums</span><span class="p">,</span> <span class="n">a</span><span class="p">.</span><span class="n">nums</span> <span class="o">+</span> <span class="n">length</span><span class="p">,</span> <span class="n">nums</span><span class="p">);</span>
        <span class="k">return</span> <span class="o">*</span><span class="k">this</span><span class="p">;</span>
<span class="p">}</span>
</code></pre></div><h4 id="bool-operator">bool operator&lt;</h4>
<blockquote>
<p>重载了小于号，好处在于可以直接利用stl进行各种排序操作了。</p>
</blockquote>
<p>注意：一定要写成const版本的成员函数，不然STL库无法调用，因为STL库中的所有比较都是基于const对象。</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-cpp" data-lang="cpp"><span class="kt">bool</span> <span class="k">operator</span><span class="o">&lt;</span><span class="p">(</span><span class="k">const</span> <span class="n">BigInteger</span> <span class="o">&amp;</span><span class="n">a</span><span class="p">)</span> <span class="k">const</span> <span class="p">{</span>
        <span class="k">if</span> <span class="p">(</span><span class="n">f</span> <span class="o">&amp;&amp;</span> <span class="o">!</span><span class="n">a</span><span class="p">.</span><span class="n">f</span><span class="p">)</span> <span class="p">{</span> <span class="c1">//其中一个为负数，则那个是更小的
</span><span class="c1"></span>            <span class="k">return</span> <span class="nb">true</span><span class="p">;</span>
        <span class="p">}</span> <span class="k">else</span> <span class="nf">if</span> <span class="p">(</span><span class="o">!</span><span class="n">f</span> <span class="o">&amp;&amp;</span> <span class="n">a</span><span class="p">.</span><span class="n">f</span><span class="p">)</span>
            <span class="k">return</span> <span class="nb">false</span><span class="p">;</span>
        <span class="k">if</span> <span class="p">(</span><span class="n">f</span><span class="p">)</span> <span class="p">{</span> <span class="c1">//两者都为负数的情况，左边的值要更大则为true
</span><span class="c1"></span>            <span class="k">return</span> <span class="nf">compare</span><span class="p">(</span><span class="o">*</span><span class="k">this</span><span class="p">,</span> <span class="n">a</span><span class="p">);</span>
        <span class="p">}</span><span class="c1">//两者均为正数，则值更小的在左边为true
</span><span class="c1"></span>        <span class="k">return</span> <span class="nf">compare</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="o">*</span><span class="k">this</span><span class="p">);</span>
<span class="p">}</span>
</code></pre></div><h4 id="核心算法biginteger-operator">(*核心算法)BigInteger operator+</h4>
<blockquote>
<p>利用静态成员函数完成无符号的加减，然后在这里进行判断各种符号情况，根据不同的符号情况进行不同的加法处理。</p>
</blockquote>
<ul>
<li>注意在调用minus之前需要比较两个数的nums谁更大，更大的放在第一个参数上！</li>
</ul>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-cpp" data-lang="cpp"><span class="n">BigInteger</span> <span class="k">operator</span><span class="o">+</span><span class="p">(</span><span class="n">BigInteger</span> <span class="o">&amp;</span><span class="n">a</span><span class="p">)</span> <span class="p">{</span>
        <span class="n">BigInteger</span> <span class="n">res</span><span class="p">;</span>
        <span class="kt">bool</span> <span class="n">flag</span><span class="p">;</span>
        <span class="k">if</span> <span class="p">(</span><span class="n">a</span><span class="p">.</span><span class="n">f</span> <span class="o">&amp;&amp;</span> <span class="n">f</span><span class="p">)</span> <span class="p">{</span> <span class="c1">//同为负数情况，直接相加，再改符号
</span><span class="c1"></span>            <span class="n">res</span> <span class="o">=</span> <span class="n">add</span><span class="p">(</span><span class="o">*</span><span class="k">this</span><span class="p">,</span> <span class="n">a</span><span class="p">);</span>
            <span class="n">flag</span> <span class="o">=</span> <span class="nb">true</span><span class="p">;</span>
        <span class="p">}</span> <span class="k">else</span> <span class="nf">if</span> <span class="p">(</span><span class="n">a</span><span class="p">.</span><span class="n">f</span> <span class="o">&amp;&amp;</span> <span class="o">!</span><span class="n">f</span><span class="p">)</span> <span class="p">{</span><span class="c1">//左正右负
</span><span class="c1"></span>            <span class="k">if</span> <span class="p">(</span><span class="n">compare</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="o">*</span><span class="k">this</span><span class="p">))</span> <span class="p">{</span> <span class="c1">//看负数对应的nums是否比正数大
</span><span class="c1"></span>                <span class="n">flag</span> <span class="o">=</span> <span class="nb">true</span><span class="p">;</span>
                <span class="n">res</span> <span class="o">=</span> <span class="n">minus</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="o">*</span><span class="k">this</span><span class="p">);</span>
            <span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
                <span class="n">flag</span> <span class="o">=</span> <span class="nb">false</span><span class="p">;</span>
                <span class="n">res</span> <span class="o">=</span> <span class="n">minus</span><span class="p">(</span><span class="o">*</span><span class="k">this</span><span class="p">,</span> <span class="n">a</span><span class="p">);</span>
            <span class="p">}</span>
        <span class="p">}</span> <span class="k">else</span> <span class="nf">if</span> <span class="p">(</span><span class="o">!</span><span class="n">a</span><span class="p">.</span><span class="n">f</span> <span class="o">&amp;&amp;</span> <span class="n">f</span><span class="p">)</span> <span class="p">{</span>
            <span class="k">if</span> <span class="p">(</span><span class="n">compare</span><span class="p">(</span><span class="o">*</span><span class="k">this</span><span class="p">,</span> <span class="n">a</span><span class="p">))</span> <span class="p">{</span> <span class="c1">//与上一个相同
</span><span class="c1"></span>                <span class="n">flag</span> <span class="o">=</span> <span class="nb">true</span><span class="p">;</span>
                <span class="n">res</span> <span class="o">=</span> <span class="n">minus</span><span class="p">(</span><span class="o">*</span><span class="k">this</span><span class="p">,</span> <span class="n">a</span><span class="p">);</span>
            <span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
                <span class="n">flag</span> <span class="o">=</span> <span class="nb">false</span><span class="p">;</span>
                <span class="n">res</span> <span class="o">=</span> <span class="n">minus</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="o">*</span><span class="k">this</span><span class="p">);</span>
            <span class="p">}</span>
        <span class="p">}</span> <span class="k">else</span> <span class="p">{</span> <span class="c1">//同时为正数就是最简单的加法
</span><span class="c1"></span>            <span class="n">flag</span> <span class="o">=</span> <span class="nb">false</span><span class="p">;</span>
            <span class="n">res</span> <span class="o">=</span> <span class="n">add</span><span class="p">(</span><span class="o">*</span><span class="k">this</span><span class="p">,</span> <span class="n">a</span><span class="p">);</span>
        <span class="p">}</span>
        <span class="n">res</span><span class="p">.</span><span class="n">f</span> <span class="o">=</span> <span class="n">flag</span><span class="p">;</span>
        <span class="k">return</span> <span class="n">res</span><span class="p">;</span>
<span class="p">}</span>
</code></pre></div><h4 id="核心算法biginteger-operator-">(*核心算法)BigInteger operator-</h4>
<blockquote>
<p>同样是分类讨论，同样是根据不同的类型调用minus和add函数。</p>
</blockquote>
<ul>
<li>与正数不同的处理在于对符号的处理，如果同为负数，则需要判断两者是否相等，防止两数相等相减后减为 <code>0</code>，而被处理为 <code>-0</code> 。</li>
</ul>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-cpp" data-lang="cpp"><span class="n">BigInteger</span> <span class="k">operator</span><span class="o">-</span><span class="p">(</span><span class="n">BigInteger</span> <span class="o">&amp;</span><span class="n">a</span><span class="p">)</span> <span class="p">{</span>
        <span class="n">BigInteger</span> <span class="n">res</span><span class="p">;</span>
        <span class="kt">bool</span> <span class="n">flag</span><span class="p">;</span>
        <span class="k">if</span> <span class="p">(</span><span class="n">a</span><span class="p">.</span><span class="n">f</span> <span class="o">&amp;&amp;</span> <span class="n">f</span><span class="p">)</span> <span class="p">{</span> <span class="c1">//同为负数情况--左边-右边==(不看符号)右边-(不看符号)左边
</span><span class="c1"></span>            <span class="k">if</span> <span class="p">(</span><span class="n">compare</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="o">*</span><span class="k">this</span><span class="p">))</span> <span class="p">{</span>
                <span class="n">flag</span> <span class="o">=</span> <span class="nb">false</span><span class="p">;</span>
                <span class="n">res</span> <span class="o">=</span> <span class="n">minus</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="o">*</span><span class="k">this</span><span class="p">);</span>
            <span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
                <span class="k">if</span> <span class="p">(</span><span class="n">isEqual</span><span class="p">(</span><span class="o">*</span><span class="k">this</span><span class="p">,</span> <span class="n">a</span><span class="p">))</span>
                    <span class="n">flag</span> <span class="o">=</span> <span class="nb">false</span><span class="p">;</span>
                <span class="k">else</span> <span class="n">flag</span> <span class="o">=</span> <span class="nb">true</span><span class="p">;</span>
                <span class="n">res</span> <span class="o">=</span> <span class="n">minus</span><span class="p">(</span><span class="o">*</span><span class="k">this</span><span class="p">,</span> <span class="n">a</span><span class="p">);</span>
            <span class="p">}</span>
        <span class="p">}</span> <span class="k">else</span> <span class="nf">if</span> <span class="p">(</span><span class="n">a</span><span class="p">.</span><span class="n">f</span> <span class="o">&amp;&amp;</span> <span class="o">!</span><span class="n">f</span><span class="p">)</span> <span class="p">{</span> <span class="c1">//左边为正，右边为负--左边-右边==左边+右边
</span><span class="c1"></span>            <span class="n">flag</span> <span class="o">=</span> <span class="nb">false</span><span class="p">;</span>
            <span class="n">res</span> <span class="o">=</span> <span class="n">add</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="o">*</span><span class="k">this</span><span class="p">);</span>
        <span class="p">}</span> <span class="k">else</span> <span class="nf">if</span> <span class="p">(</span><span class="o">!</span><span class="n">a</span><span class="p">.</span><span class="n">f</span> <span class="o">&amp;&amp;</span> <span class="n">f</span><span class="p">)</span> <span class="p">{</span> <span class="c1">//右边为正，左边为负--左边-右边==两边为负的加法
</span><span class="c1"></span>            <span class="n">flag</span> <span class="o">=</span> <span class="nb">true</span><span class="p">;</span>
            <span class="n">res</span> <span class="o">=</span> <span class="n">add</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="o">*</span><span class="k">this</span><span class="p">);</span>
        <span class="p">}</span> <span class="k">else</span> <span class="p">{</span> <span class="c1">//同时为正数--左边-右边==左边-右边(分类讨论正负
</span><span class="c1"></span>            <span class="k">if</span> <span class="p">(</span><span class="n">compare</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="o">*</span><span class="k">this</span><span class="p">))</span> <span class="p">{</span> <span class="c1">//右边&gt;左边,符号为负
</span><span class="c1"></span>                <span class="n">res</span> <span class="o">=</span> <span class="n">minus</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="o">*</span><span class="k">this</span><span class="p">);</span>
                <span class="n">flag</span> <span class="o">=</span> <span class="nb">true</span><span class="p">;</span>
            <span class="p">}</span> <span class="k">else</span> <span class="p">{</span> <span class="c1">//右边&lt;左边，符号为正
</span><span class="c1"></span>                <span class="n">res</span> <span class="o">=</span> <span class="n">minus</span><span class="p">(</span><span class="o">*</span><span class="k">this</span><span class="p">,</span> <span class="n">a</span><span class="p">);</span>
                <span class="n">flag</span> <span class="o">=</span> <span class="nb">false</span><span class="p">;</span>
            <span class="p">}</span>
        <span class="p">}</span>
        <span class="n">res</span><span class="p">.</span><span class="n">f</span> <span class="o">=</span> <span class="n">flag</span><span class="p">;</span>
        <span class="k">return</span> <span class="n">res</span><span class="p">;</span>
<span class="p">}</span>
</code></pre></div><h3 id="四其他内部成员函数详解">四、其他内部成员函数详解</h3>
<ol>
<li><strong>向外提供的get接口</strong></li>
</ol>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-cpp" data-lang="cpp">  <span class="kt">int</span> <span class="nf">getCap</span><span class="p">()</span> <span class="p">{</span>
        <span class="k">return</span> <span class="n">capacity</span><span class="p">;</span>
    <span class="p">}</span>

    <span class="kt">int</span> <span class="nf">getLength</span><span class="p">()</span> <span class="p">{</span>
        <span class="k">return</span> <span class="n">length</span><span class="p">;</span>
    <span class="p">}</span>

    <span class="kt">bool</span> <span class="nf">isNegative</span><span class="p">()</span> <span class="p">{</span>
        <span class="k">return</span> <span class="n">f</span><span class="p">;</span>
    <span class="p">}</span>

    <span class="kt">bool</span> <span class="nf">isEmpty</span><span class="p">()</span> <span class="p">{</span>
        <span class="k">return</span> <span class="n">length</span> <span class="o">==</span> <span class="mi">0</span><span class="p">;</span>
    <span class="p">}</span>
</code></pre></div><ol start="2">
<li>进行赋值操作所必备的<strong>push_back</strong>和<strong>reverse</strong>函数</li>
</ol>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-cpp" data-lang="cpp">    <span class="kt">void</span> <span class="nf">push_back</span><span class="p">(</span><span class="kt">char</span> <span class="n">x</span><span class="p">)</span> <span class="p">{</span>
        <span class="k">if</span> <span class="p">(</span><span class="n">length</span> <span class="o">&gt;=</span> <span class="n">capacity</span><span class="p">)</span> <span class="p">{</span><span class="c1">//扩容操作
</span><span class="c1"></span>            <span class="n">capacity</span> <span class="o">*=</span> <span class="mi">2</span><span class="p">;</span>
            <span class="kt">char</span> <span class="o">*</span><span class="n">t</span> <span class="o">=</span> <span class="n">nums</span><span class="p">;</span>
            <span class="n">nums</span> <span class="o">=</span> <span class="k">new</span> <span class="kt">char</span><span class="p">[</span><span class="n">capacity</span><span class="p">];</span>
            <span class="n">std</span><span class="o">::</span><span class="n">copy</span><span class="p">(</span><span class="n">t</span><span class="p">,</span> <span class="n">t</span> <span class="o">+</span> <span class="n">length</span><span class="p">,</span> <span class="n">nums</span><span class="p">);</span>
            <span class="k">delete</span><span class="p">[]</span><span class="n">t</span><span class="p">;</span>
        <span class="p">}</span>
        <span class="n">nums</span><span class="p">[</span><span class="n">length</span><span class="o">++</span><span class="p">]</span> <span class="o">=</span> <span class="n">x</span><span class="p">;</span>
    <span class="p">}</span>

    <span class="kt">void</span> <span class="nf">reverse</span><span class="p">()</span> <span class="p">{</span><span class="c1">//反转操作
</span><span class="c1"></span>        <span class="kt">int</span> <span class="n">l</span> <span class="o">=</span> <span class="mi">0</span><span class="p">,</span> <span class="n">r</span> <span class="o">=</span> <span class="n">length</span> <span class="o">-</span> <span class="mi">1</span><span class="p">;</span>
        <span class="k">while</span> <span class="p">(</span><span class="n">l</span> <span class="o">&lt;</span> <span class="n">r</span><span class="p">)</span> <span class="p">{</span>
            <span class="n">std</span><span class="o">::</span><span class="n">swap</span><span class="p">(</span><span class="n">nums</span><span class="p">[</span><span class="n">l</span><span class="p">],</span> <span class="n">nums</span><span class="p">[</span><span class="n">r</span><span class="p">]);</span>
            <span class="n">l</span><span class="o">++</span><span class="p">;</span>
            <span class="n">r</span><span class="o">--</span><span class="p">;</span>
        <span class="p">}</span>
    <span class="p">}</span>
</code></pre></div><ol start="3">
<li>无关紧要的 <code>read()</code> 输入接口 和 <code>print()</code> 输出测试接口</li>
</ol>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-cpp" data-lang="cpp">    <span class="kt">void</span> <span class="nf">print</span><span class="p">()</span> <span class="p">{</span>
        <span class="k">if</span> <span class="p">(</span><span class="n">f</span><span class="p">)</span>
            <span class="n">printf</span><span class="p">(</span><span class="s">&#34;-&#34;</span><span class="p">);</span>
        <span class="n">nums</span><span class="p">[</span><span class="n">length</span><span class="p">]</span> <span class="o">=</span> <span class="sc">&#39;\0&#39;</span><span class="p">;</span>
        <span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
        <span class="k">while</span> <span class="p">(</span><span class="n">nums</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">==</span> <span class="sc">&#39;0&#39;</span><span class="p">)</span><span class="n">i</span><span class="o">++</span><span class="p">;</span>
        <span class="n">printf</span><span class="p">(</span><span class="s">&#34;%s&#34;</span><span class="p">,</span> <span class="n">nums</span> <span class="o">+</span> <span class="n">i</span><span class="p">);</span>
    <span class="p">}</span>

    <span class="kt">void</span> <span class="nf">read</span><span class="p">()</span> <span class="p">{</span><span class="c1">//利用getchar()给对象赋上数据
</span><span class="c1"></span>        <span class="kt">char</span> <span class="n">c</span> <span class="o">=</span> <span class="n">getchar</span><span class="p">();</span>
        <span class="k">if</span> <span class="p">(</span><span class="n">c</span> <span class="o">==</span> <span class="sc">&#39;-&#39;</span><span class="p">)</span> <span class="p">{</span>
            <span class="n">f</span> <span class="o">=</span> <span class="nb">true</span><span class="p">;</span>
            <span class="n">c</span> <span class="o">=</span> <span class="n">getchar</span><span class="p">();</span>
        <span class="p">}</span>
        <span class="k">while</span> <span class="p">(</span><span class="n">c</span> <span class="o">==</span> <span class="sc">&#39;0&#39;</span><span class="p">)</span> <span class="n">c</span> <span class="o">=</span> <span class="n">getchar</span><span class="p">();</span><span class="c1">//将前导0消耗掉
</span><span class="c1"></span>        <span class="k">while</span> <span class="p">(</span><span class="n">c</span> <span class="o">!=</span> <span class="sc">&#39;\n&#39;</span><span class="p">)</span> <span class="p">{</span>
            <span class="n">push_back</span><span class="p">(</span><span class="n">c</span><span class="p">);</span><span class="c1">//不断的调用push_back即可
</span><span class="c1"></span>            <span class="n">c</span> <span class="o">=</span> <span class="n">getchar</span><span class="p">();</span>
        <span class="p">}</span>
    <span class="p">}</span>
</code></pre></div><h2 id="整理代码">整理代码</h2>
<h3 id="h声明文件">.h声明文件</h3>
<blockquote>
<p>如果在声明类的同时进行定义，则内部的成员函数默认就是内联的。所以我们一般把短小的代码进行内联，以下的实现均是以该规律进行。</p>
</blockquote>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-cpp" data-lang="cpp"><span class="c1">//
</span><span class="c1">// Created by Alone on 2021/10/7.
</span><span class="c1">//
</span><span class="c1"></span>
<span class="cp">#ifndef MY_TINY_STL_BIGINTEGER_H
</span><span class="cp">#define MY_TINY_STL_BIGINTEGER_H
</span><span class="cp"></span>
<span class="cp">#include</span> <span class="cpf">&lt;algorithm&gt;</span><span class="cp">
</span><span class="cp">#include</span> <span class="cpf">&lt;iostream&gt;</span><span class="cp">
</span><span class="cp">#include</span> <span class="cpf">&lt;cstring&gt;</span><span class="cp">
</span><span class="cp"></span>
<span class="k">class</span> <span class="nc">BigInteger</span> <span class="p">{</span>
    <span class="kt">bool</span> <span class="n">f</span><span class="p">;</span>
    <span class="kt">char</span> <span class="o">*</span><span class="n">nums</span><span class="p">;</span>
    <span class="kt">int</span> <span class="n">length</span><span class="p">;</span>
    <span class="kt">int</span> <span class="n">capacity</span><span class="p">;</span>
<span class="k">public</span><span class="o">:</span>
    <span class="c1">//构造函数
</span><span class="c1"></span>    <span class="n">BigInteger</span><span class="p">()</span> <span class="o">:</span> <span class="n">length</span><span class="p">(</span><span class="mi">0</span><span class="p">),</span> <span class="n">capacity</span><span class="p">(</span><span class="mi">1</span><span class="p">),</span> <span class="n">f</span><span class="p">(</span><span class="nb">false</span><span class="p">)</span> <span class="p">{</span> <span class="c1">//缺省构造函数
</span><span class="c1"></span>        <span class="n">nums</span> <span class="o">=</span> <span class="k">new</span> <span class="kt">char</span><span class="p">[</span><span class="n">capacity</span><span class="p">];</span>
    <span class="p">}</span>

    <span class="n">BigInteger</span><span class="p">(</span><span class="k">const</span> <span class="kt">char</span> <span class="o">*</span><span class="n">n</span><span class="p">);</span>

    <span class="n">BigInteger</span><span class="p">(</span><span class="k">const</span> <span class="n">BigInteger</span> <span class="o">&amp;</span><span class="n">a</span><span class="p">);</span>

    <span class="n">BigInteger</span><span class="p">(</span><span class="n">BigInteger</span> <span class="o">&amp;&amp;</span><span class="n">a</span><span class="p">);</span>

    <span class="o">~</span><span class="n">BigInteger</span><span class="p">()</span> <span class="p">{</span> <span class="c1">//析构函数
</span><span class="c1"></span>        <span class="k">delete</span><span class="p">[]</span> <span class="n">nums</span><span class="p">;</span>
    <span class="p">}</span>

<span class="k">public</span><span class="o">:</span>
    <span class="c1">//静态函数
</span><span class="c1"></span>    <span class="k">static</span> <span class="kt">void</span> <span class="n">Swap</span><span class="p">(</span><span class="n">BigInteger</span> <span class="o">&amp;</span><span class="n">a</span><span class="p">,</span> <span class="n">BigInteger</span> <span class="o">&amp;</span><span class="n">b</span><span class="p">);</span>

    <span class="k">static</span> <span class="kt">bool</span> <span class="nf">compare</span><span class="p">(</span><span class="k">const</span> <span class="n">BigInteger</span> <span class="o">&amp;</span><span class="n">a</span><span class="p">,</span> <span class="k">const</span> <span class="n">BigInteger</span> <span class="o">&amp;</span><span class="n">b</span><span class="p">);</span>

    <span class="kt">bool</span> <span class="nf">isEqual</span><span class="p">(</span><span class="n">BigInteger</span> <span class="o">&amp;</span><span class="n">a</span><span class="p">,</span> <span class="n">BigInteger</span> <span class="o">&amp;</span><span class="n">b</span><span class="p">);</span>

    <span class="k">static</span> <span class="n">BigInteger</span> <span class="nf">add</span><span class="p">(</span><span class="n">BigInteger</span> <span class="o">&amp;</span><span class="n">a</span><span class="p">,</span> <span class="n">BigInteger</span> <span class="o">&amp;</span><span class="n">b</span><span class="p">);</span>

    <span class="k">static</span> <span class="n">BigInteger</span> <span class="nf">minus</span><span class="p">(</span><span class="n">BigInteger</span> <span class="o">&amp;</span><span class="n">a</span><span class="p">,</span> <span class="n">BigInteger</span> <span class="o">&amp;</span><span class="n">b</span><span class="p">);</span>

<span class="k">public</span><span class="o">:</span>
    <span class="c1">//运算符重载
</span><span class="c1"></span>    <span class="kt">char</span> <span class="o">&amp;</span><span class="k">operator</span><span class="p">[](</span><span class="kt">int</span> <span class="n">i</span><span class="p">)</span> <span class="p">{</span>
        <span class="k">return</span> <span class="n">nums</span><span class="p">[</span><span class="n">i</span><span class="p">];</span>
    <span class="p">}</span>

    <span class="n">BigInteger</span> <span class="o">&amp;</span><span class="k">operator</span><span class="o">=</span><span class="p">(</span><span class="n">BigInteger</span> <span class="o">&amp;&amp;</span><span class="n">a</span><span class="p">)</span> <span class="p">{</span> <span class="c1">//Swap&amp;Copy方式实现右值赋值重载
</span><span class="c1"></span>        <span class="n">Swap</span><span class="p">(</span><span class="o">*</span><span class="k">this</span><span class="p">,</span> <span class="n">a</span><span class="p">);</span>
        <span class="k">return</span> <span class="o">*</span><span class="k">this</span><span class="p">;</span>
    <span class="p">}</span>

    <span class="n">BigInteger</span> <span class="o">&amp;</span><span class="k">operator</span><span class="o">=</span><span class="p">(</span><span class="k">const</span> <span class="n">BigInteger</span> <span class="o">&amp;</span><span class="n">a</span><span class="p">);</span>

    <span class="kt">bool</span> <span class="k">operator</span><span class="o">&lt;</span><span class="p">(</span><span class="k">const</span> <span class="n">BigInteger</span> <span class="o">&amp;</span><span class="n">a</span><span class="p">)</span> <span class="k">const</span><span class="p">;</span>

    <span class="n">BigInteger</span> <span class="k">operator</span><span class="o">+</span><span class="p">(</span><span class="n">BigInteger</span> <span class="o">&amp;</span><span class="n">a</span><span class="p">);</span>

    <span class="n">BigInteger</span> <span class="k">operator</span><span class="o">-</span><span class="p">(</span><span class="n">BigInteger</span> <span class="o">&amp;</span><span class="n">a</span><span class="p">);</span>

<span class="k">public</span><span class="o">:</span>
    <span class="c1">//对象的基本成员函数
</span><span class="c1"></span>    <span class="kt">int</span> <span class="n">getCap</span><span class="p">()</span> <span class="p">{</span>
        <span class="k">return</span> <span class="n">capacity</span><span class="p">;</span>
    <span class="p">}</span>

    <span class="kt">int</span> <span class="nf">getLength</span><span class="p">()</span> <span class="p">{</span>
        <span class="k">return</span> <span class="n">length</span><span class="p">;</span>
    <span class="p">}</span>

    <span class="kt">bool</span> <span class="nf">isNegative</span><span class="p">()</span> <span class="p">{</span>
        <span class="k">return</span> <span class="n">f</span><span class="p">;</span>
    <span class="p">}</span>

    <span class="kt">bool</span> <span class="nf">isEmpty</span><span class="p">()</span> <span class="p">{</span>
        <span class="k">return</span> <span class="n">length</span> <span class="o">==</span> <span class="mi">0</span><span class="p">;</span>
    <span class="p">}</span>

    <span class="kt">void</span> <span class="nf">reverse</span><span class="p">();</span>

    <span class="kt">void</span> <span class="nf">push_back</span><span class="p">(</span><span class="kt">char</span> <span class="n">x</span><span class="p">);</span>

    <span class="kt">void</span> <span class="nf">print</span><span class="p">();</span>

    <span class="kt">void</span> <span class="nf">read</span><span class="p">();</span>
<span class="p">};</span>


<span class="cp">#endif </span><span class="c1">//MY_TINY_STL_BIGINTEGER_H
</span><span class="c1"></span>
</code></pre></div><h3 id="cpp定义并实现">.cpp定义并实现</h3>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-cpp" data-lang="cpp"><span class="c1">//
</span><span class="c1">// Created by Alone on 2021/10/7.
</span><span class="c1">//
</span><span class="c1"></span>
<span class="cp">#include</span> <span class="cpf">&#34;BigInteger.h&#34;</span><span class="cp">
</span><span class="cp"></span>
<span class="c1">//@构造函数实现
</span><span class="c1"></span><span class="n">BigInteger</span><span class="o">::</span><span class="n">BigInteger</span><span class="p">(</span><span class="k">const</span> <span class="kt">char</span> <span class="o">*</span><span class="n">n</span><span class="p">)</span> <span class="o">:</span> <span class="n">length</span><span class="p">(</span><span class="n">strlen</span><span class="p">(</span><span class="n">n</span><span class="p">)),</span> <span class="n">f</span><span class="p">(</span><span class="nb">false</span><span class="p">)</span> <span class="p">{</span> <span class="c1">//用于初始值的构造函数
</span><span class="c1"></span>    <span class="kt">int</span> <span class="n">start</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
    <span class="k">if</span> <span class="p">(</span><span class="n">n</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">==</span> <span class="sc">&#39;-&#39;</span><span class="p">)</span> <span class="p">{</span>
        <span class="n">f</span> <span class="o">=</span> <span class="nb">true</span><span class="p">;</span>
        <span class="n">start</span><span class="o">++</span><span class="p">;</span>
    <span class="p">}</span>
    <span class="k">while</span> <span class="p">(</span><span class="n">start</span> <span class="o">&lt;</span> <span class="n">length</span> <span class="o">&amp;&amp;</span> <span class="n">n</span><span class="p">[</span><span class="n">start</span><span class="p">]</span> <span class="o">==</span> <span class="sc">&#39;0&#39;</span><span class="p">)</span><span class="n">start</span><span class="o">++</span><span class="p">;</span>
    <span class="n">capacity</span> <span class="o">=</span> <span class="n">length</span> <span class="o">*</span> <span class="mi">10</span><span class="p">;</span>
    <span class="n">nums</span> <span class="o">=</span> <span class="k">new</span> <span class="kt">char</span><span class="p">[</span><span class="n">capacity</span><span class="p">];</span>
    <span class="n">std</span><span class="o">::</span><span class="n">copy</span><span class="p">(</span><span class="n">n</span> <span class="o">+</span> <span class="n">start</span><span class="p">,</span> <span class="n">n</span> <span class="o">+</span> <span class="n">length</span><span class="p">,</span> <span class="n">nums</span><span class="p">);</span>
    <span class="n">length</span> <span class="o">=</span> <span class="n">length</span> <span class="o">-</span> <span class="n">start</span><span class="p">;</span>
<span class="p">}</span>

<span class="n">BigInteger</span><span class="o">::</span><span class="n">BigInteger</span><span class="p">(</span><span class="k">const</span> <span class="n">BigInteger</span> <span class="o">&amp;</span><span class="n">a</span><span class="p">)</span> <span class="p">{</span>  <span class="c1">//拷贝构造函数
</span><span class="c1"></span>    <span class="n">capacity</span> <span class="o">=</span> <span class="n">a</span><span class="p">.</span><span class="n">capacity</span><span class="p">;</span>
    <span class="n">length</span> <span class="o">=</span> <span class="n">a</span><span class="p">.</span><span class="n">length</span><span class="p">;</span>
    <span class="n">f</span> <span class="o">=</span> <span class="n">a</span><span class="p">.</span><span class="n">f</span><span class="p">;</span>
    <span class="n">nums</span> <span class="o">=</span> <span class="k">new</span> <span class="kt">char</span><span class="p">[</span><span class="n">capacity</span><span class="p">];</span>
    <span class="n">std</span><span class="o">::</span><span class="n">copy</span><span class="p">(</span><span class="n">a</span><span class="p">.</span><span class="n">nums</span><span class="p">,</span> <span class="n">a</span><span class="p">.</span><span class="n">nums</span> <span class="o">+</span> <span class="n">length</span><span class="p">,</span> <span class="n">nums</span><span class="p">);</span>
<span class="p">}</span>

<span class="n">BigInteger</span><span class="o">::</span><span class="n">BigInteger</span><span class="p">(</span><span class="n">BigInteger</span> <span class="o">&amp;&amp;</span><span class="n">a</span><span class="p">)</span> <span class="o">:</span> <span class="n">length</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span> <span class="p">{</span> <span class="c1">//移动构造函数
</span><span class="c1"></span>    <span class="o">*</span><span class="k">this</span> <span class="o">=</span> <span class="n">a</span><span class="p">;</span>
<span class="p">}</span>

<span class="c1">//@静态函数实现
</span><span class="c1"></span><span class="kt">void</span> <span class="n">BigInteger</span><span class="o">::</span><span class="n">Swap</span><span class="p">(</span><span class="n">BigInteger</span> <span class="o">&amp;</span><span class="n">a</span><span class="p">,</span> <span class="n">BigInteger</span> <span class="o">&amp;</span><span class="n">b</span><span class="p">)</span> <span class="p">{</span>
    <span class="n">std</span><span class="o">::</span><span class="n">swap</span><span class="p">(</span><span class="n">a</span><span class="p">.</span><span class="n">length</span><span class="p">,</span> <span class="n">b</span><span class="p">.</span><span class="n">length</span><span class="p">);</span>
    <span class="n">std</span><span class="o">::</span><span class="n">swap</span><span class="p">(</span><span class="n">a</span><span class="p">.</span><span class="n">capacity</span><span class="p">,</span> <span class="n">b</span><span class="p">.</span><span class="n">capacity</span><span class="p">);</span>
    <span class="n">std</span><span class="o">::</span><span class="n">swap</span><span class="p">(</span><span class="n">a</span><span class="p">.</span><span class="n">f</span><span class="p">,</span> <span class="n">b</span><span class="p">.</span><span class="n">f</span><span class="p">);</span>
    <span class="n">std</span><span class="o">::</span><span class="n">swap</span><span class="p">(</span><span class="n">a</span><span class="p">.</span><span class="n">nums</span><span class="p">,</span> <span class="n">b</span><span class="p">.</span><span class="n">nums</span><span class="p">);</span>
<span class="p">}</span>

<span class="kt">bool</span> <span class="n">BigInteger</span><span class="o">::</span><span class="n">compare</span><span class="p">(</span><span class="k">const</span> <span class="n">BigInteger</span> <span class="o">&amp;</span><span class="n">a</span><span class="p">,</span> <span class="k">const</span> <span class="n">BigInteger</span> <span class="o">&amp;</span><span class="n">b</span><span class="p">)</span> <span class="p">{</span>
    <span class="kt">int</span> <span class="n">n1</span> <span class="o">=</span> <span class="n">a</span><span class="p">.</span><span class="n">length</span><span class="p">;</span>
    <span class="kt">int</span> <span class="n">n2</span> <span class="o">=</span> <span class="n">b</span><span class="p">.</span><span class="n">length</span><span class="p">;</span>
    <span class="k">if</span> <span class="p">(</span><span class="n">n1</span> <span class="o">!=</span> <span class="n">n2</span><span class="p">)</span><span class="k">return</span> <span class="n">n1</span> <span class="o">&gt;</span> <span class="n">n2</span><span class="p">;</span> <span class="c1">//返回a和b哪个大，true则位a大
</span><span class="c1"></span>    <span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
    <span class="k">while</span> <span class="p">(</span><span class="n">i</span> <span class="o">&lt;</span> <span class="n">n1</span> <span class="o">&amp;&amp;</span> <span class="n">a</span><span class="p">.</span><span class="n">nums</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">==</span> <span class="n">b</span><span class="p">.</span><span class="n">nums</span><span class="p">[</span><span class="n">i</span><span class="p">])</span><span class="n">i</span><span class="o">++</span><span class="p">;</span> <span class="c1">//a b一样长的情况下，比较两个的值
</span><span class="c1"></span>    <span class="k">if</span> <span class="p">(</span><span class="n">i</span> <span class="o">==</span> <span class="n">n1</span><span class="p">)</span>
        <span class="k">return</span> <span class="nb">false</span><span class="p">;</span>
    <span class="k">return</span> <span class="n">a</span><span class="p">.</span><span class="n">nums</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">&gt;</span> <span class="n">b</span><span class="p">.</span><span class="n">nums</span><span class="p">[</span><span class="n">i</span><span class="p">];</span>
<span class="p">}</span>

<span class="kt">bool</span> <span class="n">BigInteger</span><span class="o">::</span><span class="n">isEqual</span><span class="p">(</span><span class="n">BigInteger</span> <span class="o">&amp;</span><span class="n">a</span><span class="p">,</span> <span class="n">BigInteger</span> <span class="o">&amp;</span><span class="n">b</span><span class="p">)</span> <span class="p">{</span>
    <span class="k">if</span> <span class="p">(</span><span class="n">a</span><span class="p">.</span><span class="n">f</span> <span class="o">!=</span> <span class="n">b</span><span class="p">.</span><span class="n">f</span> <span class="o">||</span> <span class="p">(</span><span class="n">a</span><span class="p">.</span><span class="n">length</span> <span class="o">!=</span> <span class="n">b</span><span class="p">.</span><span class="n">length</span><span class="p">))</span><span class="k">return</span> <span class="nb">false</span><span class="p">;</span>
    <span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
    <span class="k">while</span> <span class="p">(</span><span class="n">i</span> <span class="o">&lt;</span> <span class="n">a</span><span class="p">.</span><span class="n">length</span> <span class="o">&amp;&amp;</span> <span class="n">a</span><span class="p">.</span><span class="n">nums</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">==</span> <span class="n">b</span><span class="p">.</span><span class="n">nums</span><span class="p">[</span><span class="n">i</span><span class="p">])</span><span class="n">i</span><span class="o">++</span><span class="p">;</span>
    <span class="k">return</span> <span class="n">i</span> <span class="o">==</span> <span class="n">a</span><span class="p">.</span><span class="n">length</span> <span class="o">&amp;&amp;</span> <span class="n">a</span><span class="p">.</span><span class="n">f</span> <span class="o">==</span> <span class="n">b</span><span class="p">.</span><span class="n">f</span><span class="p">;</span>
<span class="p">}</span>

<span class="n">BigInteger</span> <span class="n">BigInteger</span><span class="o">::</span><span class="n">add</span><span class="p">(</span><span class="n">BigInteger</span> <span class="o">&amp;</span><span class="n">a</span><span class="p">,</span> <span class="n">BigInteger</span> <span class="o">&amp;</span><span class="n">b</span><span class="p">)</span> <span class="p">{</span>
    <span class="n">a</span><span class="p">.</span><span class="n">reverse</span><span class="p">();</span><span class="c1">//尾端对齐
</span><span class="c1"></span>    <span class="n">b</span><span class="p">.</span><span class="n">reverse</span><span class="p">();</span>
    <span class="n">BigInteger</span> <span class="n">t</span><span class="p">;</span>
    <span class="kt">int</span> <span class="n">up</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
    <span class="kt">int</span> <span class="n">len</span> <span class="o">=</span> <span class="n">a</span><span class="p">.</span><span class="n">length</span> <span class="o">&gt;</span> <span class="n">b</span><span class="p">.</span><span class="n">length</span> <span class="o">?</span> <span class="n">a</span><span class="p">.</span><span class="nl">length</span> <span class="p">:</span> <span class="n">b</span><span class="p">.</span><span class="n">length</span><span class="p">;</span>
    <span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o">&lt;</span> <span class="n">len</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span> <span class="p">{</span>
        <span class="kt">int</span> <span class="n">ta</span> <span class="o">=</span> <span class="n">i</span> <span class="o">&lt;</span> <span class="n">a</span><span class="p">.</span><span class="n">length</span> <span class="o">?</span> <span class="n">a</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">-</span> <span class="sc">&#39;0&#39;</span> <span class="o">:</span> <span class="mi">0</span><span class="p">;</span>
        <span class="kt">int</span> <span class="n">tb</span> <span class="o">=</span> <span class="n">i</span> <span class="o">&lt;</span> <span class="n">b</span><span class="p">.</span><span class="n">length</span> <span class="o">?</span> <span class="n">b</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">-</span> <span class="sc">&#39;0&#39;</span> <span class="o">:</span> <span class="mi">0</span><span class="p">;</span>
        <span class="kt">int</span> <span class="n">base</span> <span class="o">=</span> <span class="n">ta</span> <span class="o">+</span> <span class="n">tb</span> <span class="o">+</span> <span class="n">up</span><span class="p">;</span>
        <span class="n">t</span><span class="p">.</span><span class="n">push_back</span><span class="p">(</span><span class="n">base</span> <span class="o">%</span> <span class="mi">10</span> <span class="o">+</span> <span class="sc">&#39;0&#39;</span><span class="p">);</span>
        <span class="n">up</span> <span class="o">=</span> <span class="n">base</span> <span class="o">/</span> <span class="mi">10</span><span class="p">;</span>
    <span class="p">}</span>
    <span class="k">if</span> <span class="p">(</span><span class="n">up</span><span class="p">)</span>
        <span class="n">t</span><span class="p">.</span><span class="n">push_back</span><span class="p">(</span><span class="n">up</span> <span class="o">+</span> <span class="sc">&#39;0&#39;</span><span class="p">);</span>
    <span class="n">t</span><span class="p">.</span><span class="n">reverse</span><span class="p">();</span><span class="c1">//返回原位
</span><span class="c1"></span>    <span class="n">a</span><span class="p">.</span><span class="n">reverse</span><span class="p">();</span>
    <span class="n">b</span><span class="p">.</span><span class="n">reverse</span><span class="p">();</span>
    <span class="k">return</span> <span class="n">t</span><span class="p">;</span>
<span class="p">}</span>

<span class="n">BigInteger</span> <span class="n">BigInteger</span><span class="o">::</span><span class="n">minus</span><span class="p">(</span><span class="n">BigInteger</span> <span class="o">&amp;</span><span class="n">a</span><span class="p">,</span> <span class="n">BigInteger</span> <span class="o">&amp;</span><span class="n">b</span><span class="p">)</span> <span class="p">{</span>
    <span class="n">a</span><span class="p">.</span><span class="n">reverse</span><span class="p">();</span>
    <span class="n">b</span><span class="p">.</span><span class="n">reverse</span><span class="p">();</span>
    <span class="n">BigInteger</span> <span class="n">t</span><span class="p">;</span>
    <span class="kt">int</span> <span class="n">len</span> <span class="o">=</span> <span class="n">a</span><span class="p">.</span><span class="n">length</span> <span class="o">&gt;</span> <span class="n">b</span><span class="p">.</span><span class="n">length</span> <span class="o">?</span> <span class="n">a</span><span class="p">.</span><span class="nl">length</span> <span class="p">:</span> <span class="n">b</span><span class="p">.</span><span class="n">length</span><span class="p">;</span>
    <span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o">&lt;</span> <span class="n">len</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span> <span class="p">{</span>
        <span class="kt">int</span> <span class="n">ta</span> <span class="o">=</span> <span class="n">i</span> <span class="o">&lt;</span> <span class="n">a</span><span class="p">.</span><span class="n">length</span> <span class="o">?</span> <span class="n">a</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">-</span> <span class="sc">&#39;0&#39;</span> <span class="o">:</span> <span class="mi">0</span><span class="p">;</span>
        <span class="kt">int</span> <span class="n">tb</span> <span class="o">=</span> <span class="n">i</span> <span class="o">&lt;</span> <span class="n">b</span><span class="p">.</span><span class="n">length</span> <span class="o">?</span> <span class="n">b</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">-</span> <span class="sc">&#39;0&#39;</span> <span class="o">:</span> <span class="mi">0</span><span class="p">;</span>
        <span class="kt">int</span> <span class="n">base</span> <span class="o">=</span> <span class="n">ta</span> <span class="o">-</span> <span class="n">tb</span><span class="p">;</span>
        <span class="k">if</span> <span class="p">(</span><span class="n">base</span> <span class="o">&lt;</span> <span class="mi">0</span><span class="p">)</span> <span class="p">{</span>
            <span class="n">base</span> <span class="o">+=</span> <span class="mi">10</span><span class="p">;</span>
            <span class="n">a</span><span class="p">[</span><span class="n">i</span> <span class="o">+</span> <span class="mi">1</span><span class="p">]</span><span class="o">--</span><span class="p">;</span>
        <span class="p">}</span>
        <span class="n">t</span><span class="p">.</span><span class="n">push_back</span><span class="p">(</span><span class="n">base</span> <span class="o">+</span> <span class="sc">&#39;0&#39;</span><span class="p">);</span>
    <span class="p">}</span>
    <span class="n">t</span><span class="p">.</span><span class="n">reverse</span><span class="p">();</span>
    <span class="n">a</span><span class="p">.</span><span class="n">reverse</span><span class="p">();</span>
    <span class="n">b</span><span class="p">.</span><span class="n">reverse</span><span class="p">();</span>
    <span class="k">return</span> <span class="n">t</span><span class="p">;</span>
<span class="p">}</span>


<span class="c1">//@运算符重载实现
</span><span class="c1"></span><span class="n">BigInteger</span> <span class="o">&amp;</span><span class="n">BigInteger</span><span class="o">::</span><span class="k">operator</span><span class="o">=</span><span class="p">(</span><span class="k">const</span> <span class="n">BigInteger</span> <span class="o">&amp;</span><span class="n">a</span><span class="p">)</span> <span class="p">{</span>
    <span class="k">if</span> <span class="p">(</span><span class="n">length</span> <span class="o">!=</span> <span class="mi">0</span><span class="p">)</span><span class="c1">//如果不是初始化调用的 = ，则肯定需要先把原来的内存delete掉
</span><span class="c1"></span>        <span class="k">delete</span><span class="p">[]</span><span class="n">nums</span><span class="p">;</span>
    <span class="n">capacity</span> <span class="o">=</span> <span class="n">a</span><span class="p">.</span><span class="n">capacity</span><span class="p">;</span>
    <span class="n">length</span> <span class="o">=</span> <span class="n">a</span><span class="p">.</span><span class="n">length</span><span class="p">;</span>
    <span class="n">f</span> <span class="o">=</span> <span class="n">a</span><span class="p">.</span><span class="n">f</span><span class="p">;</span>
    <span class="n">nums</span> <span class="o">=</span> <span class="k">new</span> <span class="kt">char</span><span class="p">[</span><span class="n">capacity</span><span class="p">];</span>
    <span class="n">std</span><span class="o">::</span><span class="n">copy</span><span class="p">(</span><span class="n">a</span><span class="p">.</span><span class="n">nums</span><span class="p">,</span> <span class="n">a</span><span class="p">.</span><span class="n">nums</span> <span class="o">+</span> <span class="n">length</span><span class="p">,</span> <span class="n">nums</span><span class="p">);</span>
    <span class="k">return</span> <span class="o">*</span><span class="k">this</span><span class="p">;</span>
<span class="p">}</span>

<span class="n">BigInteger</span> <span class="n">BigInteger</span><span class="o">::</span><span class="k">operator</span><span class="o">+</span><span class="p">(</span><span class="n">BigInteger</span> <span class="o">&amp;</span><span class="n">a</span><span class="p">)</span> <span class="p">{</span>
    <span class="n">BigInteger</span> <span class="n">res</span><span class="p">;</span>
    <span class="kt">bool</span> <span class="n">flag</span><span class="p">;</span>
    <span class="k">if</span> <span class="p">(</span><span class="n">a</span><span class="p">.</span><span class="n">f</span> <span class="o">&amp;&amp;</span> <span class="n">f</span><span class="p">)</span> <span class="p">{</span> <span class="c1">//同为负数情况，直接相加，再改符号
</span><span class="c1"></span>        <span class="n">res</span> <span class="o">=</span> <span class="n">add</span><span class="p">(</span><span class="o">*</span><span class="k">this</span><span class="p">,</span> <span class="n">a</span><span class="p">);</span>
        <span class="n">flag</span> <span class="o">=</span> <span class="nb">true</span><span class="p">;</span>
    <span class="p">}</span> <span class="k">else</span> <span class="nf">if</span> <span class="p">(</span><span class="n">a</span><span class="p">.</span><span class="n">f</span> <span class="o">&amp;&amp;</span> <span class="o">!</span><span class="n">f</span><span class="p">)</span> <span class="p">{</span><span class="c1">//左正右负
</span><span class="c1"></span>        <span class="k">if</span> <span class="p">(</span><span class="n">compare</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="o">*</span><span class="k">this</span><span class="p">))</span> <span class="p">{</span> <span class="c1">//看负数对应的nums是否比正数大
</span><span class="c1"></span>            <span class="n">flag</span> <span class="o">=</span> <span class="nb">true</span><span class="p">;</span>
            <span class="n">res</span> <span class="o">=</span> <span class="n">minus</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="o">*</span><span class="k">this</span><span class="p">);</span>
        <span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
            <span class="n">flag</span> <span class="o">=</span> <span class="nb">false</span><span class="p">;</span>
            <span class="n">res</span> <span class="o">=</span> <span class="n">minus</span><span class="p">(</span><span class="o">*</span><span class="k">this</span><span class="p">,</span> <span class="n">a</span><span class="p">);</span>
        <span class="p">}</span>
    <span class="p">}</span> <span class="k">else</span> <span class="nf">if</span> <span class="p">(</span><span class="o">!</span><span class="n">a</span><span class="p">.</span><span class="n">f</span> <span class="o">&amp;&amp;</span> <span class="n">f</span><span class="p">)</span> <span class="p">{</span>
        <span class="k">if</span> <span class="p">(</span><span class="n">compare</span><span class="p">(</span><span class="o">*</span><span class="k">this</span><span class="p">,</span> <span class="n">a</span><span class="p">))</span> <span class="p">{</span> <span class="c1">//与上一个相同
</span><span class="c1"></span>            <span class="n">flag</span> <span class="o">=</span> <span class="nb">true</span><span class="p">;</span>
            <span class="n">res</span> <span class="o">=</span> <span class="n">minus</span><span class="p">(</span><span class="o">*</span><span class="k">this</span><span class="p">,</span> <span class="n">a</span><span class="p">);</span>
        <span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
            <span class="n">flag</span> <span class="o">=</span> <span class="nb">false</span><span class="p">;</span>
            <span class="n">res</span> <span class="o">=</span> <span class="n">minus</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="o">*</span><span class="k">this</span><span class="p">);</span>
        <span class="p">}</span>
    <span class="p">}</span> <span class="k">else</span> <span class="p">{</span> <span class="c1">//同时为正数就是最简单的加法
</span><span class="c1"></span>        <span class="n">flag</span> <span class="o">=</span> <span class="nb">false</span><span class="p">;</span>
        <span class="n">res</span> <span class="o">=</span> <span class="n">add</span><span class="p">(</span><span class="o">*</span><span class="k">this</span><span class="p">,</span> <span class="n">a</span><span class="p">);</span>
    <span class="p">}</span>
    <span class="n">res</span><span class="p">.</span><span class="n">f</span> <span class="o">=</span> <span class="n">flag</span><span class="p">;</span>
    <span class="k">return</span> <span class="n">res</span><span class="p">;</span>
<span class="p">}</span>

<span class="n">BigInteger</span> <span class="n">BigInteger</span><span class="o">::</span><span class="k">operator</span><span class="o">-</span><span class="p">(</span><span class="n">BigInteger</span> <span class="o">&amp;</span><span class="n">a</span><span class="p">)</span> <span class="p">{</span>
    <span class="n">BigInteger</span> <span class="n">res</span><span class="p">;</span>
    <span class="kt">bool</span> <span class="n">flag</span><span class="p">;</span>
    <span class="k">if</span> <span class="p">(</span><span class="n">a</span><span class="p">.</span><span class="n">f</span> <span class="o">&amp;&amp;</span> <span class="n">f</span><span class="p">)</span> <span class="p">{</span> <span class="c1">//同为负数情况--左边-右边==(不看符号)右边-(不看符号)左边
</span><span class="c1"></span>        <span class="k">if</span> <span class="p">(</span><span class="n">compare</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="o">*</span><span class="k">this</span><span class="p">))</span> <span class="p">{</span>
            <span class="n">flag</span> <span class="o">=</span> <span class="nb">false</span><span class="p">;</span>
            <span class="n">res</span> <span class="o">=</span> <span class="n">minus</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="o">*</span><span class="k">this</span><span class="p">);</span>
        <span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
            <span class="k">if</span> <span class="p">(</span><span class="n">isEqual</span><span class="p">(</span><span class="o">*</span><span class="k">this</span><span class="p">,</span> <span class="n">a</span><span class="p">))</span>
                <span class="n">flag</span> <span class="o">=</span> <span class="nb">false</span><span class="p">;</span>
            <span class="k">else</span> <span class="n">flag</span> <span class="o">=</span> <span class="nb">true</span><span class="p">;</span>
            <span class="n">res</span> <span class="o">=</span> <span class="n">minus</span><span class="p">(</span><span class="o">*</span><span class="k">this</span><span class="p">,</span> <span class="n">a</span><span class="p">);</span>
        <span class="p">}</span>
    <span class="p">}</span> <span class="k">else</span> <span class="nf">if</span> <span class="p">(</span><span class="n">a</span><span class="p">.</span><span class="n">f</span> <span class="o">&amp;&amp;</span> <span class="o">!</span><span class="n">f</span><span class="p">)</span> <span class="p">{</span> <span class="c1">//左边为正，右边为负--左边-右边==左边+右边
</span><span class="c1"></span>        <span class="n">flag</span> <span class="o">=</span> <span class="nb">false</span><span class="p">;</span>
        <span class="n">res</span> <span class="o">=</span> <span class="n">add</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="o">*</span><span class="k">this</span><span class="p">);</span>
    <span class="p">}</span> <span class="k">else</span> <span class="nf">if</span> <span class="p">(</span><span class="o">!</span><span class="n">a</span><span class="p">.</span><span class="n">f</span> <span class="o">&amp;&amp;</span> <span class="n">f</span><span class="p">)</span> <span class="p">{</span> <span class="c1">//右边为正，左边为负--左边-右边==两边为负的加法
</span><span class="c1"></span>        <span class="n">flag</span> <span class="o">=</span> <span class="nb">true</span><span class="p">;</span>
        <span class="n">res</span> <span class="o">=</span> <span class="n">add</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="o">*</span><span class="k">this</span><span class="p">);</span>
    <span class="p">}</span> <span class="k">else</span> <span class="p">{</span> <span class="c1">//同时为正数--左边-右边==左边-右边(分类讨论正负
</span><span class="c1"></span>        <span class="k">if</span> <span class="p">(</span><span class="n">compare</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="o">*</span><span class="k">this</span><span class="p">))</span> <span class="p">{</span> <span class="c1">//右边&gt;左边,符号为负
</span><span class="c1"></span>            <span class="n">res</span> <span class="o">=</span> <span class="n">minus</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="o">*</span><span class="k">this</span><span class="p">);</span>
            <span class="n">flag</span> <span class="o">=</span> <span class="nb">true</span><span class="p">;</span>
        <span class="p">}</span> <span class="k">else</span> <span class="p">{</span> <span class="c1">//右边&lt;左边，符号为正
</span><span class="c1"></span>            <span class="n">res</span> <span class="o">=</span> <span class="n">minus</span><span class="p">(</span><span class="o">*</span><span class="k">this</span><span class="p">,</span> <span class="n">a</span><span class="p">);</span>
            <span class="n">flag</span> <span class="o">=</span> <span class="nb">false</span><span class="p">;</span>
        <span class="p">}</span>
    <span class="p">}</span>
    <span class="n">res</span><span class="p">.</span><span class="n">f</span> <span class="o">=</span> <span class="n">flag</span><span class="p">;</span>
    <span class="k">return</span> <span class="n">res</span><span class="p">;</span>
<span class="p">}</span>

<span class="kt">bool</span> <span class="n">BigInteger</span><span class="o">::</span><span class="k">operator</span><span class="o">&lt;</span><span class="p">(</span><span class="k">const</span> <span class="n">BigInteger</span> <span class="o">&amp;</span><span class="n">a</span><span class="p">)</span> <span class="k">const</span> <span class="p">{</span>
    <span class="k">if</span> <span class="p">(</span><span class="n">f</span> <span class="o">&amp;&amp;</span> <span class="o">!</span><span class="n">a</span><span class="p">.</span><span class="n">f</span><span class="p">)</span> <span class="p">{</span> <span class="c1">//其中一个为负数，则那个是更小的
</span><span class="c1"></span>        <span class="k">return</span> <span class="nb">true</span><span class="p">;</span>
    <span class="p">}</span> <span class="k">else</span> <span class="nf">if</span> <span class="p">(</span><span class="o">!</span><span class="n">f</span> <span class="o">&amp;&amp;</span> <span class="n">a</span><span class="p">.</span><span class="n">f</span><span class="p">)</span>
        <span class="k">return</span> <span class="nb">false</span><span class="p">;</span>
    <span class="k">if</span> <span class="p">(</span><span class="n">f</span><span class="p">)</span> <span class="p">{</span> <span class="c1">//两者都为负数的情况，左边的值要更大则为true
</span><span class="c1"></span>        <span class="k">return</span> <span class="nf">compare</span><span class="p">(</span><span class="o">*</span><span class="k">this</span><span class="p">,</span> <span class="n">a</span><span class="p">);</span>
    <span class="p">}</span><span class="c1">//两者均为正数，则值更小的在左边为true
</span><span class="c1"></span>    <span class="k">return</span> <span class="nf">compare</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="o">*</span><span class="k">this</span><span class="p">);</span>
<span class="p">}</span>


<span class="c1">//@基本成员函数
</span><span class="c1"></span><span class="kt">void</span> <span class="n">BigInteger</span><span class="o">::</span><span class="n">reverse</span><span class="p">()</span> <span class="p">{</span>
    <span class="kt">int</span> <span class="n">l</span> <span class="o">=</span> <span class="mi">0</span><span class="p">,</span> <span class="n">r</span> <span class="o">=</span> <span class="n">length</span> <span class="o">-</span> <span class="mi">1</span><span class="p">;</span>
    <span class="k">while</span> <span class="p">(</span><span class="n">l</span> <span class="o">&lt;</span> <span class="n">r</span><span class="p">)</span> <span class="p">{</span>
        <span class="n">std</span><span class="o">::</span><span class="n">swap</span><span class="p">(</span><span class="n">nums</span><span class="p">[</span><span class="n">l</span><span class="p">],</span> <span class="n">nums</span><span class="p">[</span><span class="n">r</span><span class="p">]);</span>
        <span class="n">l</span><span class="o">++</span><span class="p">;</span>
        <span class="n">r</span><span class="o">--</span><span class="p">;</span>
    <span class="p">}</span>
<span class="p">}</span>

<span class="kt">void</span> <span class="n">BigInteger</span><span class="o">::</span><span class="n">push_back</span><span class="p">(</span><span class="kt">char</span> <span class="n">x</span><span class="p">)</span> <span class="p">{</span>
    <span class="k">if</span> <span class="p">(</span><span class="n">length</span> <span class="o">&gt;=</span> <span class="n">capacity</span><span class="p">)</span> <span class="p">{</span>
        <span class="n">capacity</span> <span class="o">*=</span> <span class="mi">2</span><span class="p">;</span>
        <span class="kt">char</span> <span class="o">*</span><span class="n">t</span> <span class="o">=</span> <span class="n">nums</span><span class="p">;</span>
        <span class="n">nums</span> <span class="o">=</span> <span class="k">new</span> <span class="kt">char</span><span class="p">[</span><span class="n">capacity</span><span class="p">];</span>
        <span class="n">std</span><span class="o">::</span><span class="n">copy</span><span class="p">(</span><span class="n">t</span><span class="p">,</span> <span class="n">t</span> <span class="o">+</span> <span class="n">length</span><span class="p">,</span> <span class="n">nums</span><span class="p">);</span>
        <span class="k">delete</span><span class="p">[]</span><span class="n">t</span><span class="p">;</span>
    <span class="p">}</span>
    <span class="n">nums</span><span class="p">[</span><span class="n">length</span><span class="o">++</span><span class="p">]</span> <span class="o">=</span> <span class="n">x</span><span class="p">;</span>
<span class="p">}</span>

<span class="kt">void</span> <span class="n">BigInteger</span><span class="o">::</span><span class="n">print</span><span class="p">()</span> <span class="p">{</span>
    <span class="k">if</span> <span class="p">(</span><span class="n">f</span><span class="p">)</span>
        <span class="n">printf</span><span class="p">(</span><span class="s">&#34;-&#34;</span><span class="p">);</span>
    <span class="n">nums</span><span class="p">[</span><span class="n">length</span><span class="p">]</span> <span class="o">=</span> <span class="sc">&#39;\0&#39;</span><span class="p">;</span>
    <span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
    <span class="k">while</span> <span class="p">(</span><span class="n">nums</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">==</span> <span class="sc">&#39;0&#39;</span><span class="p">)</span><span class="n">i</span><span class="o">++</span><span class="p">;</span>
    <span class="n">printf</span><span class="p">(</span><span class="s">&#34;%s&#34;</span><span class="p">,</span> <span class="n">nums</span> <span class="o">+</span> <span class="n">i</span><span class="p">);</span>
<span class="p">}</span>

<span class="kt">void</span> <span class="n">BigInteger</span><span class="o">::</span><span class="n">read</span><span class="p">()</span> <span class="p">{</span>
    <span class="kt">char</span> <span class="n">c</span> <span class="o">=</span> <span class="n">getchar</span><span class="p">();</span>
    <span class="k">if</span> <span class="p">(</span><span class="n">c</span> <span class="o">==</span> <span class="sc">&#39;-&#39;</span><span class="p">)</span> <span class="p">{</span>
        <span class="n">f</span> <span class="o">=</span> <span class="nb">true</span><span class="p">;</span>
        <span class="n">c</span> <span class="o">=</span> <span class="n">getchar</span><span class="p">();</span>
    <span class="p">}</span>
    <span class="k">while</span> <span class="p">(</span><span class="n">c</span> <span class="o">==</span> <span class="sc">&#39;0&#39;</span><span class="p">)</span> <span class="n">c</span> <span class="o">=</span> <span class="n">getchar</span><span class="p">();</span><span class="c1">//将前导0消耗掉
</span><span class="c1"></span>    <span class="k">while</span> <span class="p">(</span><span class="n">c</span> <span class="o">!=</span> <span class="sc">&#39;\n&#39;</span><span class="p">)</span> <span class="p">{</span>
        <span class="n">push_back</span><span class="p">(</span><span class="n">c</span><span class="p">);</span><span class="c1">//不断的调用push_back即可
</span><span class="c1"></span>        <span class="n">c</span> <span class="o">=</span> <span class="n">getchar</span><span class="p">();</span>
    <span class="p">}</span>
<span class="p">}</span>
</code></pre></div><h2 id="功能测试">功能测试</h2>
<h3 id="一基本的加减测试">一、基本的加减测试</h3>
<p>运行的测试代码：</p>
<p><img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://img-blog.csdnimg.cn/5b69900c92a0405b87f1331c42522714.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBAQ19ZQ0JYIFB5X1lZRFM=,size_20,color_FFFFFF,t_70,g_se,x_16"
        data-srcset="https://img-blog.csdnimg.cn/5b69900c92a0405b87f1331c42522714.png?x-oss-process=image/watermark%2ctype_ZHJvaWRzYW5zZmFsbGJhY2s%2cshadow_50%2ctext_Q1NETiBAQ19ZQ0JYIFB5X1lZRFM=%2csize_20%2ccolor_FFFFFF%2ct_70%2cg_se%2cx_16, https://img-blog.csdnimg.cn/5b69900c92a0405b87f1331c42522714.png?x-oss-process=image/watermark%2ctype_ZHJvaWRzYW5zZmFsbGJhY2s%2cshadow_50%2ctext_Q1NETiBAQ19ZQ0JYIFB5X1lZRFM=%2csize_20%2ccolor_FFFFFF%2ct_70%2cg_se%2cx_16 1.5x, https://img-blog.csdnimg.cn/5b69900c92a0405b87f1331c42522714.png?x-oss-process=image/watermark%2ctype_ZHJvaWRzYW5zZmFsbGJhY2s%2cshadow_50%2ctext_Q1NETiBAQ19ZQ0JYIFB5X1lZRFM=%2csize_20%2ccolor_FFFFFF%2ct_70%2cg_se%2cx_16 2x"
        data-sizes="auto"
        alt="https://img-blog.csdnimg.cn/5b69900c92a0405b87f1331c42522714.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBAQ19ZQ0JYIFB5X1lZRFM=,size_20,color_FFFFFF,t_70,g_se,x_16"
        title="https://img-blog.csdnimg.cn/5b69900c92a0405b87f1331c42522714.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBAQ19ZQ0JYIFB5X1lZRFM=,size_20,color_FFFFFF,t_70,g_se,x_16" /></p>
<p><strong>打印输出</strong></p>
<p><img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://img-blog.csdnimg.cn/adbedb183abb48f2b4457f5ce49d509a.png"
        data-srcset="https://img-blog.csdnimg.cn/adbedb183abb48f2b4457f5ce49d509a.png, https://img-blog.csdnimg.cn/adbedb183abb48f2b4457f5ce49d509a.png 1.5x, https://img-blog.csdnimg.cn/adbedb183abb48f2b4457f5ce49d509a.png 2x"
        data-sizes="auto"
        alt="https://img-blog.csdnimg.cn/adbedb183abb48f2b4457f5ce49d509a.png"
        title="https://img-blog.csdnimg.cn/adbedb183abb48f2b4457f5ce49d509a.png" /></p>
<p><strong>python输出</strong></p>
<p><img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://img-blog.csdnimg.cn/5e9223aad22b4dd5944465982b6de2e8.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBAQ19ZQ0JYIFB5X1lZRFM=,size_20,color_FFFFFF,t_70,g_se,x_16"
        data-srcset="https://img-blog.csdnimg.cn/5e9223aad22b4dd5944465982b6de2e8.png?x-oss-process=image/watermark%2ctype_ZHJvaWRzYW5zZmFsbGJhY2s%2cshadow_50%2ctext_Q1NETiBAQ19ZQ0JYIFB5X1lZRFM=%2csize_20%2ccolor_FFFFFF%2ct_70%2cg_se%2cx_16, https://img-blog.csdnimg.cn/5e9223aad22b4dd5944465982b6de2e8.png?x-oss-process=image/watermark%2ctype_ZHJvaWRzYW5zZmFsbGJhY2s%2cshadow_50%2ctext_Q1NETiBAQ19ZQ0JYIFB5X1lZRFM=%2csize_20%2ccolor_FFFFFF%2ct_70%2cg_se%2cx_16 1.5x, https://img-blog.csdnimg.cn/5e9223aad22b4dd5944465982b6de2e8.png?x-oss-process=image/watermark%2ctype_ZHJvaWRzYW5zZmFsbGJhY2s%2cshadow_50%2ctext_Q1NETiBAQ19ZQ0JYIFB5X1lZRFM=%2csize_20%2ccolor_FFFFFF%2ct_70%2cg_se%2cx_16 2x"
        data-sizes="auto"
        alt="https://img-blog.csdnimg.cn/5e9223aad22b4dd5944465982b6de2e8.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBAQ19ZQ0JYIFB5X1lZRFM=,size_20,color_FFFFFF,t_70,g_se,x_16"
        title="https://img-blog.csdnimg.cn/5e9223aad22b4dd5944465982b6de2e8.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBAQ19ZQ0JYIFB5X1lZRFM=,size_20,color_FFFFFF,t_70,g_se,x_16" /></p>
<ul>
<li>总结</li>
</ul>
<p>与python输出无异，故通过测试。但碍于测试数据太过少，不是很有说服力，还有后面的解题测试。</p>
<h3 id="二存储个人输入的数据排序测试">二、存储个人输入的数据+排序测试</h3>
<p>测试代码(方便测试只输入了10个数据)：</p>
<p><img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://img-blog.csdnimg.cn/0033d03daa18465e942b81d24d923dc5.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBAQ19ZQ0JYIFB5X1lZRFM=,size_18,color_FFFFFF,t_70,g_se,x_16"
        data-srcset="https://img-blog.csdnimg.cn/0033d03daa18465e942b81d24d923dc5.png?x-oss-process=image/watermark%2ctype_ZHJvaWRzYW5zZmFsbGJhY2s%2cshadow_50%2ctext_Q1NETiBAQ19ZQ0JYIFB5X1lZRFM=%2csize_18%2ccolor_FFFFFF%2ct_70%2cg_se%2cx_16, https://img-blog.csdnimg.cn/0033d03daa18465e942b81d24d923dc5.png?x-oss-process=image/watermark%2ctype_ZHJvaWRzYW5zZmFsbGJhY2s%2cshadow_50%2ctext_Q1NETiBAQ19ZQ0JYIFB5X1lZRFM=%2csize_18%2ccolor_FFFFFF%2ct_70%2cg_se%2cx_16 1.5x, https://img-blog.csdnimg.cn/0033d03daa18465e942b81d24d923dc5.png?x-oss-process=image/watermark%2ctype_ZHJvaWRzYW5zZmFsbGJhY2s%2cshadow_50%2ctext_Q1NETiBAQ19ZQ0JYIFB5X1lZRFM=%2csize_18%2ccolor_FFFFFF%2ct_70%2cg_se%2cx_16 2x"
        data-sizes="auto"
        alt="https://img-blog.csdnimg.cn/0033d03daa18465e942b81d24d923dc5.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBAQ19ZQ0JYIFB5X1lZRFM=,size_18,color_FFFFFF,t_70,g_se,x_16"
        title="https://img-blog.csdnimg.cn/0033d03daa18465e942b81d24d923dc5.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBAQ19ZQ0JYIFB5X1lZRFM=,size_18,color_FFFFFF,t_70,g_se,x_16" /></p>
<p><strong>排序输出</strong>：</p>
<p><img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://img-blog.csdnimg.cn/cb0ff4bcb4d54214a0f5f4d7115c25d6.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBAQ19ZQ0JYIFB5X1lZRFM=,size_20,color_FFFFFF,t_70,g_se,x_16"
        data-srcset="https://img-blog.csdnimg.cn/cb0ff4bcb4d54214a0f5f4d7115c25d6.png?x-oss-process=image/watermark%2ctype_ZHJvaWRzYW5zZmFsbGJhY2s%2cshadow_50%2ctext_Q1NETiBAQ19ZQ0JYIFB5X1lZRFM=%2csize_20%2ccolor_FFFFFF%2ct_70%2cg_se%2cx_16, https://img-blog.csdnimg.cn/cb0ff4bcb4d54214a0f5f4d7115c25d6.png?x-oss-process=image/watermark%2ctype_ZHJvaWRzYW5zZmFsbGJhY2s%2cshadow_50%2ctext_Q1NETiBAQ19ZQ0JYIFB5X1lZRFM=%2csize_20%2ccolor_FFFFFF%2ct_70%2cg_se%2cx_16 1.5x, https://img-blog.csdnimg.cn/cb0ff4bcb4d54214a0f5f4d7115c25d6.png?x-oss-process=image/watermark%2ctype_ZHJvaWRzYW5zZmFsbGJhY2s%2cshadow_50%2ctext_Q1NETiBAQ19ZQ0JYIFB5X1lZRFM=%2csize_20%2ccolor_FFFFFF%2ct_70%2cg_se%2cx_16 2x"
        data-sizes="auto"
        alt="https://img-blog.csdnimg.cn/cb0ff4bcb4d54214a0f5f4d7115c25d6.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBAQ19ZQ0JYIFB5X1lZRFM=,size_20,color_FFFFFF,t_70,g_se,x_16"
        title="https://img-blog.csdnimg.cn/cb0ff4bcb4d54214a0f5f4d7115c25d6.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBAQ19ZQ0JYIFB5X1lZRFM=,size_20,color_FFFFFF,t_70,g_se,x_16" /></p>
<h3 id="三解题测试">三、解题测试</h3>
<p>正好最近刷的PAT甲级就涉及到大数的加减hhh！</p>
<p><strong>题目描述</strong></p>
<p><img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://img-blog.csdnimg.cn/906e22e7b96b461fac32403e917d5383.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBAQ19ZQ0JYIFB5X1lZRFM=,size_20,color_FFFFFF,t_70,g_se,x_16"
        data-srcset="https://img-blog.csdnimg.cn/906e22e7b96b461fac32403e917d5383.png?x-oss-process=image/watermark%2ctype_ZHJvaWRzYW5zZmFsbGJhY2s%2cshadow_50%2ctext_Q1NETiBAQ19ZQ0JYIFB5X1lZRFM=%2csize_20%2ccolor_FFFFFF%2ct_70%2cg_se%2cx_16, https://img-blog.csdnimg.cn/906e22e7b96b461fac32403e917d5383.png?x-oss-process=image/watermark%2ctype_ZHJvaWRzYW5zZmFsbGJhY2s%2cshadow_50%2ctext_Q1NETiBAQ19ZQ0JYIFB5X1lZRFM=%2csize_20%2ccolor_FFFFFF%2ct_70%2cg_se%2cx_16 1.5x, https://img-blog.csdnimg.cn/906e22e7b96b461fac32403e917d5383.png?x-oss-process=image/watermark%2ctype_ZHJvaWRzYW5zZmFsbGJhY2s%2cshadow_50%2ctext_Q1NETiBAQ19ZQ0JYIFB5X1lZRFM=%2csize_20%2ccolor_FFFFFF%2ct_70%2cg_se%2cx_16 2x"
        data-sizes="auto"
        alt="https://img-blog.csdnimg.cn/906e22e7b96b461fac32403e917d5383.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBAQ19ZQ0JYIFB5X1lZRFM=,size_20,color_FFFFFF,t_70,g_se,x_16"
        title="https://img-blog.csdnimg.cn/906e22e7b96b461fac32403e917d5383.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBAQ19ZQ0JYIFB5X1lZRFM=,size_20,color_FFFFFF,t_70,g_se,x_16" />
<a href="https://www.nowcoder.com/pat/5/problem/4116" target="_blank" rel="noopener noreffer">OJ平台</a></p>
<p><strong>解题代码</strong></p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-cpp" data-lang="cpp"><span class="cp">#include</span> <span class="cpf">&#34;bits/stdc++.h&#34;</span><span class="cp">
</span><span class="cp"></span>
<span class="k">class</span> <span class="nc">BigInteger</span> <span class="p">{</span>
    <span class="kt">bool</span> <span class="n">f</span><span class="p">;</span>
    <span class="kt">char</span> <span class="o">*</span><span class="n">nums</span><span class="p">;</span>
    <span class="kt">int</span> <span class="n">length</span><span class="p">;</span>
    <span class="kt">int</span> <span class="n">capacity</span><span class="p">;</span>
<span class="k">public</span><span class="o">:</span><span class="c1">//构造函数
</span><span class="c1"></span>    <span class="n">BigInteger</span><span class="p">()</span> <span class="o">:</span> <span class="n">length</span><span class="p">(</span><span class="mi">0</span><span class="p">),</span> <span class="n">capacity</span><span class="p">(</span><span class="mi">1</span><span class="p">),</span> <span class="n">f</span><span class="p">(</span><span class="nb">false</span><span class="p">)</span> <span class="p">{</span> <span class="c1">//缺省构造函数
</span><span class="c1"></span>        <span class="n">nums</span> <span class="o">=</span> <span class="k">new</span> <span class="kt">char</span><span class="p">[</span><span class="n">capacity</span><span class="p">];</span>
    <span class="p">}</span>

    <span class="n">BigInteger</span><span class="p">(</span><span class="k">const</span> <span class="kt">char</span> <span class="o">*</span><span class="n">n</span><span class="p">)</span> <span class="o">:</span> <span class="n">length</span><span class="p">(</span><span class="n">strlen</span><span class="p">(</span><span class="n">n</span><span class="p">)),</span> <span class="n">f</span><span class="p">(</span><span class="nb">false</span><span class="p">)</span> <span class="p">{</span> <span class="c1">//用于初始值的构造函数
</span><span class="c1"></span>        <span class="kt">int</span> <span class="n">start</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
        <span class="k">if</span> <span class="p">(</span><span class="n">n</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">==</span> <span class="sc">&#39;-&#39;</span><span class="p">)</span> <span class="p">{</span>
            <span class="n">f</span> <span class="o">=</span> <span class="nb">true</span><span class="p">;</span>
            <span class="n">start</span><span class="o">++</span><span class="p">;</span>
        <span class="p">}</span>
        <span class="k">while</span> <span class="p">(</span><span class="n">start</span> <span class="o">&lt;</span> <span class="n">length</span> <span class="o">&amp;&amp;</span> <span class="n">n</span><span class="p">[</span><span class="n">start</span><span class="p">]</span> <span class="o">==</span> <span class="sc">&#39;0&#39;</span><span class="p">)</span><span class="n">start</span><span class="o">++</span><span class="p">;</span>
        <span class="n">capacity</span> <span class="o">=</span> <span class="n">length</span> <span class="o">*</span> <span class="mi">10</span><span class="p">;</span>
        <span class="n">nums</span> <span class="o">=</span> <span class="k">new</span> <span class="kt">char</span><span class="p">[</span><span class="n">capacity</span><span class="p">];</span>
        <span class="n">std</span><span class="o">::</span><span class="n">copy</span><span class="p">(</span><span class="n">n</span> <span class="o">+</span> <span class="n">start</span><span class="p">,</span> <span class="n">n</span> <span class="o">+</span> <span class="n">length</span><span class="p">,</span> <span class="n">nums</span><span class="p">);</span>
        <span class="n">length</span> <span class="o">=</span> <span class="n">length</span> <span class="o">-</span> <span class="n">start</span><span class="p">;</span>
    <span class="p">}</span>

    <span class="n">BigInteger</span><span class="p">(</span><span class="k">const</span> <span class="n">BigInteger</span> <span class="o">&amp;</span><span class="n">a</span><span class="p">)</span> <span class="p">{</span>  <span class="c1">//拷贝构造函数
</span><span class="c1"></span>        <span class="n">capacity</span> <span class="o">=</span> <span class="n">a</span><span class="p">.</span><span class="n">capacity</span><span class="p">;</span>
        <span class="n">length</span> <span class="o">=</span> <span class="n">a</span><span class="p">.</span><span class="n">length</span><span class="p">;</span>
        <span class="n">f</span> <span class="o">=</span> <span class="n">a</span><span class="p">.</span><span class="n">f</span><span class="p">;</span>
        <span class="n">nums</span> <span class="o">=</span> <span class="k">new</span> <span class="kt">char</span><span class="p">[</span><span class="n">capacity</span><span class="p">];</span>
        <span class="n">std</span><span class="o">::</span><span class="n">copy</span><span class="p">(</span><span class="n">a</span><span class="p">.</span><span class="n">nums</span><span class="p">,</span> <span class="n">a</span><span class="p">.</span><span class="n">nums</span> <span class="o">+</span> <span class="n">length</span><span class="p">,</span> <span class="n">nums</span><span class="p">);</span>
    <span class="p">}</span>

    <span class="n">BigInteger</span><span class="p">(</span><span class="n">BigInteger</span> <span class="o">&amp;&amp;</span><span class="n">a</span><span class="p">)</span> <span class="o">:</span> <span class="n">length</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span> <span class="p">{</span> <span class="c1">//移动构造函数
</span><span class="c1"></span>        <span class="o">*</span><span class="k">this</span> <span class="o">=</span> <span class="n">a</span><span class="p">;</span>
    <span class="p">}</span>

    <span class="o">~</span><span class="n">BigInteger</span><span class="p">()</span> <span class="p">{</span> <span class="c1">//析构函数
</span><span class="c1"></span>        <span class="k">delete</span><span class="p">[]</span> <span class="n">nums</span><span class="p">;</span>
    <span class="p">}</span>

<span class="k">public</span><span class="o">:</span><span class="c1">//静态成员函数
</span><span class="c1"></span>    <span class="k">static</span> <span class="kt">void</span> <span class="n">Swap</span><span class="p">(</span><span class="n">BigInteger</span> <span class="o">&amp;</span><span class="n">a</span><span class="p">,</span> <span class="n">BigInteger</span> <span class="o">&amp;</span><span class="n">b</span><span class="p">)</span> <span class="p">{</span>
        <span class="n">std</span><span class="o">::</span><span class="n">swap</span><span class="p">(</span><span class="n">a</span><span class="p">.</span><span class="n">length</span><span class="p">,</span> <span class="n">b</span><span class="p">.</span><span class="n">length</span><span class="p">);</span>
        <span class="n">std</span><span class="o">::</span><span class="n">swap</span><span class="p">(</span><span class="n">a</span><span class="p">.</span><span class="n">capacity</span><span class="p">,</span> <span class="n">b</span><span class="p">.</span><span class="n">capacity</span><span class="p">);</span>
        <span class="n">std</span><span class="o">::</span><span class="n">swap</span><span class="p">(</span><span class="n">a</span><span class="p">.</span><span class="n">f</span><span class="p">,</span> <span class="n">b</span><span class="p">.</span><span class="n">f</span><span class="p">);</span>
        <span class="n">std</span><span class="o">::</span><span class="n">swap</span><span class="p">(</span><span class="n">a</span><span class="p">.</span><span class="n">nums</span><span class="p">,</span> <span class="n">b</span><span class="p">.</span><span class="n">nums</span><span class="p">);</span>
    <span class="p">}</span>

    <span class="k">static</span> <span class="kt">bool</span> <span class="nf">compare</span><span class="p">(</span><span class="k">const</span> <span class="n">BigInteger</span> <span class="o">&amp;</span><span class="n">a</span><span class="p">,</span> <span class="k">const</span> <span class="n">BigInteger</span> <span class="o">&amp;</span><span class="n">b</span><span class="p">)</span> <span class="p">{</span> <span class="c1">//比较纯nums大小(不看符号
</span><span class="c1"></span>        <span class="kt">int</span> <span class="n">n1</span> <span class="o">=</span> <span class="n">a</span><span class="p">.</span><span class="n">length</span><span class="p">;</span>
        <span class="kt">int</span> <span class="n">n2</span> <span class="o">=</span> <span class="n">b</span><span class="p">.</span><span class="n">length</span><span class="p">;</span>
        <span class="k">if</span> <span class="p">(</span><span class="n">n1</span> <span class="o">!=</span> <span class="n">n2</span><span class="p">)</span><span class="k">return</span> <span class="n">n1</span> <span class="o">&gt;</span> <span class="n">n2</span><span class="p">;</span> <span class="c1">//返回a和b哪个大，true则位a大
</span><span class="c1"></span>        <span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
        <span class="k">while</span> <span class="p">(</span><span class="n">i</span> <span class="o">&lt;</span> <span class="n">n1</span> <span class="o">&amp;&amp;</span> <span class="n">a</span><span class="p">.</span><span class="n">nums</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">==</span> <span class="n">b</span><span class="p">.</span><span class="n">nums</span><span class="p">[</span><span class="n">i</span><span class="p">])</span><span class="n">i</span><span class="o">++</span><span class="p">;</span> <span class="c1">//a b一样长的情况下，比较两个的值
</span><span class="c1"></span>        <span class="k">if</span> <span class="p">(</span><span class="n">i</span> <span class="o">==</span> <span class="n">n1</span><span class="p">)</span>
            <span class="k">return</span> <span class="nb">false</span><span class="p">;</span>
        <span class="k">return</span> <span class="n">a</span><span class="p">.</span><span class="n">nums</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">&gt;</span> <span class="n">b</span><span class="p">.</span><span class="n">nums</span><span class="p">[</span><span class="n">i</span><span class="p">];</span>
    <span class="p">}</span>

    <span class="kt">bool</span> <span class="nf">isEqual</span><span class="p">(</span><span class="n">BigInteger</span> <span class="o">&amp;</span><span class="n">a</span><span class="p">,</span> <span class="n">BigInteger</span> <span class="o">&amp;</span><span class="n">b</span><span class="p">)</span> <span class="p">{</span>
        <span class="k">if</span> <span class="p">(</span><span class="n">a</span><span class="p">.</span><span class="n">f</span> <span class="o">!=</span> <span class="n">b</span><span class="p">.</span><span class="n">f</span> <span class="o">||</span> <span class="p">(</span><span class="n">a</span><span class="p">.</span><span class="n">length</span> <span class="o">!=</span> <span class="n">b</span><span class="p">.</span><span class="n">length</span><span class="p">))</span><span class="k">return</span> <span class="nb">false</span><span class="p">;</span>
        <span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
        <span class="k">while</span> <span class="p">(</span><span class="n">i</span> <span class="o">&lt;</span> <span class="n">a</span><span class="p">.</span><span class="n">length</span> <span class="o">&amp;&amp;</span> <span class="n">a</span><span class="p">.</span><span class="n">nums</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">==</span> <span class="n">b</span><span class="p">.</span><span class="n">nums</span><span class="p">[</span><span class="n">i</span><span class="p">])</span><span class="n">i</span><span class="o">++</span><span class="p">;</span>
        <span class="k">return</span> <span class="n">i</span> <span class="o">==</span> <span class="n">a</span><span class="p">.</span><span class="n">length</span> <span class="o">&amp;&amp;</span> <span class="n">a</span><span class="p">.</span><span class="n">f</span> <span class="o">==</span> <span class="n">b</span><span class="p">.</span><span class="n">f</span><span class="p">;</span>
    <span class="p">}</span>

    <span class="k">static</span> <span class="n">BigInteger</span> <span class="nf">add</span><span class="p">(</span><span class="n">BigInteger</span> <span class="o">&amp;</span><span class="n">a</span><span class="p">,</span> <span class="n">BigInteger</span> <span class="o">&amp;</span><span class="n">b</span><span class="p">)</span> <span class="p">{</span> <span class="c1">//不看符号的加法
</span><span class="c1"></span>        <span class="n">a</span><span class="p">.</span><span class="n">reverse</span><span class="p">();</span><span class="c1">//尾端对齐
</span><span class="c1"></span>        <span class="n">b</span><span class="p">.</span><span class="n">reverse</span><span class="p">();</span>
        <span class="n">BigInteger</span> <span class="n">t</span><span class="p">;</span>
        <span class="kt">int</span> <span class="n">up</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
        <span class="kt">int</span> <span class="n">len</span> <span class="o">=</span> <span class="n">a</span><span class="p">.</span><span class="n">length</span> <span class="o">&gt;</span> <span class="n">b</span><span class="p">.</span><span class="n">length</span> <span class="o">?</span> <span class="n">a</span><span class="p">.</span><span class="nl">length</span> <span class="p">:</span> <span class="n">b</span><span class="p">.</span><span class="n">length</span><span class="p">;</span>
        <span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o">&lt;</span> <span class="n">len</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span> <span class="p">{</span>
            <span class="kt">int</span> <span class="n">ta</span> <span class="o">=</span> <span class="n">i</span> <span class="o">&lt;</span> <span class="n">a</span><span class="p">.</span><span class="n">length</span> <span class="o">?</span> <span class="n">a</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">-</span> <span class="sc">&#39;0&#39;</span> <span class="o">:</span> <span class="mi">0</span><span class="p">;</span>
            <span class="kt">int</span> <span class="n">tb</span> <span class="o">=</span> <span class="n">i</span> <span class="o">&lt;</span> <span class="n">b</span><span class="p">.</span><span class="n">length</span> <span class="o">?</span> <span class="n">b</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">-</span> <span class="sc">&#39;0&#39;</span> <span class="o">:</span> <span class="mi">0</span><span class="p">;</span>
            <span class="kt">int</span> <span class="n">base</span> <span class="o">=</span> <span class="n">ta</span> <span class="o">+</span> <span class="n">tb</span> <span class="o">+</span> <span class="n">up</span><span class="p">;</span>
            <span class="n">t</span><span class="p">.</span><span class="n">push_back</span><span class="p">(</span><span class="n">base</span> <span class="o">%</span> <span class="mi">10</span> <span class="o">+</span> <span class="sc">&#39;0&#39;</span><span class="p">);</span>
            <span class="n">up</span> <span class="o">=</span> <span class="n">base</span> <span class="o">/</span> <span class="mi">10</span><span class="p">;</span>
        <span class="p">}</span>
        <span class="k">if</span> <span class="p">(</span><span class="n">up</span><span class="p">)</span>
            <span class="n">t</span><span class="p">.</span><span class="n">push_back</span><span class="p">(</span><span class="n">up</span> <span class="o">+</span> <span class="sc">&#39;0&#39;</span><span class="p">);</span>
        <span class="n">t</span><span class="p">.</span><span class="n">reverse</span><span class="p">();</span><span class="c1">//返回原位
</span><span class="c1"></span>        <span class="n">a</span><span class="p">.</span><span class="n">reverse</span><span class="p">();</span>
        <span class="n">b</span><span class="p">.</span><span class="n">reverse</span><span class="p">();</span>
        <span class="k">return</span> <span class="n">t</span><span class="p">;</span>
    <span class="p">}</span>

    <span class="k">static</span> <span class="n">BigInteger</span> <span class="nf">minus</span><span class="p">(</span><span class="n">BigInteger</span> <span class="o">&amp;</span><span class="n">a</span><span class="p">,</span> <span class="n">BigInteger</span> <span class="o">&amp;</span><span class="n">b</span><span class="p">)</span> <span class="p">{</span> <span class="c1">//不看符号的减法,默认了a的长度或者大小是比b要大的(所以外界不要乱调用
</span><span class="c1"></span>        <span class="n">a</span><span class="p">.</span><span class="n">reverse</span><span class="p">();</span>
        <span class="n">b</span><span class="p">.</span><span class="n">reverse</span><span class="p">();</span>
        <span class="n">BigInteger</span> <span class="n">t</span><span class="p">;</span>
        <span class="kt">int</span> <span class="n">len</span> <span class="o">=</span> <span class="n">a</span><span class="p">.</span><span class="n">length</span> <span class="o">&gt;</span> <span class="n">b</span><span class="p">.</span><span class="n">length</span> <span class="o">?</span> <span class="n">a</span><span class="p">.</span><span class="nl">length</span> <span class="p">:</span> <span class="n">b</span><span class="p">.</span><span class="n">length</span><span class="p">;</span>
        <span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o">&lt;</span> <span class="n">len</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span> <span class="p">{</span>
            <span class="kt">int</span> <span class="n">ta</span> <span class="o">=</span> <span class="n">i</span> <span class="o">&lt;</span> <span class="n">a</span><span class="p">.</span><span class="n">length</span> <span class="o">?</span> <span class="n">a</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">-</span> <span class="sc">&#39;0&#39;</span> <span class="o">:</span> <span class="mi">0</span><span class="p">;</span>
            <span class="kt">int</span> <span class="n">tb</span> <span class="o">=</span> <span class="n">i</span> <span class="o">&lt;</span> <span class="n">b</span><span class="p">.</span><span class="n">length</span> <span class="o">?</span> <span class="n">b</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">-</span> <span class="sc">&#39;0&#39;</span> <span class="o">:</span> <span class="mi">0</span><span class="p">;</span>
            <span class="kt">int</span> <span class="n">base</span> <span class="o">=</span> <span class="n">ta</span> <span class="o">-</span> <span class="n">tb</span><span class="p">;</span>
            <span class="k">if</span> <span class="p">(</span><span class="n">base</span> <span class="o">&lt;</span> <span class="mi">0</span><span class="p">)</span> <span class="p">{</span>
                <span class="n">base</span> <span class="o">+=</span> <span class="mi">10</span><span class="p">;</span>
                <span class="n">a</span><span class="p">[</span><span class="n">i</span> <span class="o">+</span> <span class="mi">1</span><span class="p">]</span><span class="o">--</span><span class="p">;</span>
            <span class="p">}</span>
            <span class="n">t</span><span class="p">.</span><span class="n">push_back</span><span class="p">(</span><span class="n">base</span> <span class="o">+</span> <span class="sc">&#39;0&#39;</span><span class="p">);</span>
        <span class="p">}</span>
        <span class="n">t</span><span class="p">.</span><span class="n">reverse</span><span class="p">();</span>
        <span class="n">a</span><span class="p">.</span><span class="n">reverse</span><span class="p">();</span>
        <span class="n">b</span><span class="p">.</span><span class="n">reverse</span><span class="p">();</span>
        <span class="k">return</span> <span class="n">t</span><span class="p">;</span>
    <span class="p">}</span>

<span class="k">public</span><span class="o">:</span><span class="c1">//成员函数和重载运算符
</span><span class="c1"></span>    <span class="kt">char</span> <span class="o">&amp;</span><span class="k">operator</span><span class="p">[](</span><span class="kt">int</span> <span class="n">i</span><span class="p">)</span> <span class="p">{</span>
        <span class="k">return</span> <span class="n">nums</span><span class="p">[</span><span class="n">i</span><span class="p">];</span>
    <span class="p">}</span>

    <span class="n">BigInteger</span> <span class="o">&amp;</span><span class="k">operator</span><span class="o">=</span><span class="p">(</span><span class="n">BigInteger</span> <span class="o">&amp;&amp;</span><span class="n">a</span><span class="p">)</span> <span class="p">{</span> <span class="c1">//Swap&amp;Copy方式实现右值赋值重载
</span><span class="c1"></span>        <span class="n">Swap</span><span class="p">(</span><span class="o">*</span><span class="k">this</span><span class="p">,</span> <span class="n">a</span><span class="p">);</span>
        <span class="k">return</span> <span class="o">*</span><span class="k">this</span><span class="p">;</span>
    <span class="p">}</span>

    <span class="n">BigInteger</span> <span class="o">&amp;</span><span class="k">operator</span><span class="o">=</span><span class="p">(</span><span class="k">const</span> <span class="n">BigInteger</span> <span class="o">&amp;</span><span class="n">a</span><span class="p">)</span> <span class="p">{</span><span class="c1">//深拷贝
</span><span class="c1"></span>        <span class="k">if</span> <span class="p">(</span><span class="n">length</span> <span class="o">!=</span> <span class="mi">0</span><span class="p">)</span><span class="c1">//如果不是初始化调用的 = ，则肯定需要先把原来的内存delete掉
</span><span class="c1"></span>            <span class="k">delete</span><span class="p">[]</span><span class="n">nums</span><span class="p">;</span>
        <span class="n">capacity</span> <span class="o">=</span> <span class="n">a</span><span class="p">.</span><span class="n">capacity</span><span class="p">;</span>
        <span class="n">length</span> <span class="o">=</span> <span class="n">a</span><span class="p">.</span><span class="n">length</span><span class="p">;</span>
        <span class="n">f</span> <span class="o">=</span> <span class="n">a</span><span class="p">.</span><span class="n">f</span><span class="p">;</span>
        <span class="n">nums</span> <span class="o">=</span> <span class="k">new</span> <span class="kt">char</span><span class="p">[</span><span class="n">capacity</span><span class="p">];</span>
        <span class="n">std</span><span class="o">::</span><span class="n">copy</span><span class="p">(</span><span class="n">a</span><span class="p">.</span><span class="n">nums</span><span class="p">,</span> <span class="n">a</span><span class="p">.</span><span class="n">nums</span> <span class="o">+</span> <span class="n">length</span><span class="p">,</span> <span class="n">nums</span><span class="p">);</span>
        <span class="k">return</span> <span class="o">*</span><span class="k">this</span><span class="p">;</span>
    <span class="p">}</span>

    <span class="kt">int</span> <span class="nf">getCap</span><span class="p">()</span> <span class="p">{</span>
        <span class="k">return</span> <span class="n">capacity</span><span class="p">;</span>
    <span class="p">}</span>

        <span class="kt">int</span> <span class="nf">getLength</span><span class="p">()</span> <span class="p">{</span>
            <span class="k">return</span> <span class="n">length</span><span class="p">;</span>
        <span class="p">}</span>

    <span class="kt">bool</span> <span class="nf">isNegative</span><span class="p">()</span> <span class="p">{</span>
        <span class="k">return</span> <span class="n">f</span><span class="p">;</span>
    <span class="p">}</span>

    <span class="kt">bool</span> <span class="nf">isEmpty</span><span class="p">()</span> <span class="p">{</span>
        <span class="k">return</span> <span class="n">length</span> <span class="o">==</span> <span class="mi">0</span><span class="p">;</span>
    <span class="p">}</span>

    <span class="kt">void</span> <span class="nf">reverse</span><span class="p">()</span> <span class="p">{</span>
        <span class="kt">int</span> <span class="n">l</span> <span class="o">=</span> <span class="mi">0</span><span class="p">,</span> <span class="n">r</span> <span class="o">=</span> <span class="n">length</span> <span class="o">-</span> <span class="mi">1</span><span class="p">;</span>
        <span class="k">while</span> <span class="p">(</span><span class="n">l</span> <span class="o">&lt;</span> <span class="n">r</span><span class="p">)</span> <span class="p">{</span>
            <span class="n">std</span><span class="o">::</span><span class="n">swap</span><span class="p">(</span><span class="n">nums</span><span class="p">[</span><span class="n">l</span><span class="p">],</span> <span class="n">nums</span><span class="p">[</span><span class="n">r</span><span class="p">]);</span>
            <span class="n">l</span><span class="o">++</span><span class="p">;</span>
            <span class="n">r</span><span class="o">--</span><span class="p">;</span>
        <span class="p">}</span>
    <span class="p">}</span>

    <span class="kt">void</span> <span class="nf">push_back</span><span class="p">(</span><span class="kt">char</span> <span class="n">x</span><span class="p">)</span> <span class="p">{</span>
        <span class="k">if</span> <span class="p">(</span><span class="n">length</span> <span class="o">&gt;=</span> <span class="n">capacity</span><span class="p">)</span> <span class="p">{</span>
            <span class="n">capacity</span> <span class="o">*=</span> <span class="mi">2</span><span class="p">;</span>
            <span class="kt">char</span> <span class="o">*</span><span class="n">t</span> <span class="o">=</span> <span class="n">nums</span><span class="p">;</span>
            <span class="n">nums</span> <span class="o">=</span> <span class="k">new</span> <span class="kt">char</span><span class="p">[</span><span class="n">capacity</span><span class="p">];</span>
            <span class="n">std</span><span class="o">::</span><span class="n">copy</span><span class="p">(</span><span class="n">t</span><span class="p">,</span> <span class="n">t</span> <span class="o">+</span> <span class="n">length</span><span class="p">,</span> <span class="n">nums</span><span class="p">);</span>
            <span class="k">delete</span><span class="p">[]</span><span class="n">t</span><span class="p">;</span>
        <span class="p">}</span>
        <span class="n">nums</span><span class="p">[</span><span class="n">length</span><span class="o">++</span><span class="p">]</span> <span class="o">=</span> <span class="n">x</span><span class="p">;</span>
    <span class="p">}</span>

    <span class="kt">bool</span> <span class="k">operator</span><span class="o">&lt;</span><span class="p">(</span><span class="k">const</span> <span class="n">BigInteger</span> <span class="o">&amp;</span><span class="n">a</span><span class="p">)</span> <span class="k">const</span> <span class="p">{</span>
        <span class="k">if</span> <span class="p">(</span><span class="n">f</span> <span class="o">&amp;&amp;</span> <span class="o">!</span><span class="n">a</span><span class="p">.</span><span class="n">f</span><span class="p">)</span> <span class="p">{</span> <span class="c1">//其中一个为负数，则那个是更小的
</span><span class="c1"></span>            <span class="k">return</span> <span class="nb">true</span><span class="p">;</span>
        <span class="p">}</span> <span class="k">else</span> <span class="nf">if</span> <span class="p">(</span><span class="o">!</span><span class="n">f</span> <span class="o">&amp;&amp;</span> <span class="n">a</span><span class="p">.</span><span class="n">f</span><span class="p">)</span>
            <span class="k">return</span> <span class="nb">false</span><span class="p">;</span>
        <span class="k">if</span> <span class="p">(</span><span class="n">f</span><span class="p">)</span> <span class="p">{</span> <span class="c1">//两者都为负数的情况，左边的值要更大则为true
</span><span class="c1"></span>            <span class="k">return</span> <span class="nf">compare</span><span class="p">(</span><span class="o">*</span><span class="k">this</span><span class="p">,</span> <span class="n">a</span><span class="p">);</span>
        <span class="p">}</span><span class="c1">//两者均为正数，则值更小的在左边为true
</span><span class="c1"></span>        <span class="k">return</span> <span class="nf">compare</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="o">*</span><span class="k">this</span><span class="p">);</span>
    <span class="p">}</span>

    <span class="n">BigInteger</span> <span class="k">operator</span><span class="o">+</span><span class="p">(</span><span class="n">BigInteger</span> <span class="o">&amp;</span><span class="n">a</span><span class="p">)</span> <span class="p">{</span>
        <span class="n">BigInteger</span> <span class="n">res</span><span class="p">;</span>
        <span class="kt">bool</span> <span class="n">flag</span><span class="p">;</span>
        <span class="k">if</span> <span class="p">(</span><span class="n">a</span><span class="p">.</span><span class="n">f</span> <span class="o">&amp;&amp;</span> <span class="n">f</span><span class="p">)</span> <span class="p">{</span> <span class="c1">//同为负数情况，直接相加，再改符号
</span><span class="c1"></span>            <span class="n">res</span> <span class="o">=</span> <span class="n">add</span><span class="p">(</span><span class="o">*</span><span class="k">this</span><span class="p">,</span> <span class="n">a</span><span class="p">);</span>
            <span class="n">flag</span> <span class="o">=</span> <span class="nb">true</span><span class="p">;</span>
        <span class="p">}</span> <span class="k">else</span> <span class="nf">if</span> <span class="p">(</span><span class="n">a</span><span class="p">.</span><span class="n">f</span> <span class="o">&amp;&amp;</span> <span class="o">!</span><span class="n">f</span><span class="p">)</span> <span class="p">{</span><span class="c1">//左正右负
</span><span class="c1"></span>            <span class="k">if</span> <span class="p">(</span><span class="n">compare</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="o">*</span><span class="k">this</span><span class="p">))</span> <span class="p">{</span> <span class="c1">//看负数对应的nums是否比正数大
</span><span class="c1"></span>                <span class="n">flag</span> <span class="o">=</span> <span class="nb">true</span><span class="p">;</span>
                <span class="n">res</span> <span class="o">=</span> <span class="n">minus</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="o">*</span><span class="k">this</span><span class="p">);</span>
            <span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
                <span class="n">flag</span> <span class="o">=</span> <span class="nb">false</span><span class="p">;</span>
                <span class="n">res</span> <span class="o">=</span> <span class="n">minus</span><span class="p">(</span><span class="o">*</span><span class="k">this</span><span class="p">,</span> <span class="n">a</span><span class="p">);</span>
            <span class="p">}</span>
        <span class="p">}</span> <span class="k">else</span> <span class="nf">if</span> <span class="p">(</span><span class="o">!</span><span class="n">a</span><span class="p">.</span><span class="n">f</span> <span class="o">&amp;&amp;</span> <span class="n">f</span><span class="p">)</span> <span class="p">{</span>
            <span class="k">if</span> <span class="p">(</span><span class="n">compare</span><span class="p">(</span><span class="o">*</span><span class="k">this</span><span class="p">,</span> <span class="n">a</span><span class="p">))</span> <span class="p">{</span> <span class="c1">//与上一个相同
</span><span class="c1"></span>                <span class="n">flag</span> <span class="o">=</span> <span class="nb">true</span><span class="p">;</span>
                <span class="n">res</span> <span class="o">=</span> <span class="n">minus</span><span class="p">(</span><span class="o">*</span><span class="k">this</span><span class="p">,</span> <span class="n">a</span><span class="p">);</span>
            <span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
                <span class="n">flag</span> <span class="o">=</span> <span class="nb">false</span><span class="p">;</span>
                <span class="n">res</span> <span class="o">=</span> <span class="n">minus</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="o">*</span><span class="k">this</span><span class="p">);</span>
            <span class="p">}</span>
        <span class="p">}</span> <span class="k">else</span> <span class="p">{</span> <span class="c1">//同时为正数就是最简单的加法
</span><span class="c1"></span>            <span class="n">flag</span> <span class="o">=</span> <span class="nb">false</span><span class="p">;</span>
            <span class="n">res</span> <span class="o">=</span> <span class="n">add</span><span class="p">(</span><span class="o">*</span><span class="k">this</span><span class="p">,</span> <span class="n">a</span><span class="p">);</span>
        <span class="p">}</span>
        <span class="n">res</span><span class="p">.</span><span class="n">f</span> <span class="o">=</span> <span class="n">flag</span><span class="p">;</span>
        <span class="k">return</span> <span class="n">res</span><span class="p">;</span>
    <span class="p">}</span>

    <span class="n">BigInteger</span> <span class="k">operator</span><span class="o">-</span><span class="p">(</span><span class="n">BigInteger</span> <span class="o">&amp;</span><span class="n">a</span><span class="p">)</span> <span class="p">{</span>
        <span class="n">BigInteger</span> <span class="n">res</span><span class="p">;</span>
        <span class="kt">bool</span> <span class="n">flag</span><span class="p">;</span>
        <span class="k">if</span> <span class="p">(</span><span class="n">a</span><span class="p">.</span><span class="n">f</span> <span class="o">&amp;&amp;</span> <span class="n">f</span><span class="p">)</span> <span class="p">{</span> <span class="c1">//同为负数情况--左边-右边==(不看符号)右边-(不看符号)左边
</span><span class="c1"></span>            <span class="k">if</span> <span class="p">(</span><span class="n">compare</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="o">*</span><span class="k">this</span><span class="p">))</span> <span class="p">{</span>
                <span class="n">flag</span> <span class="o">=</span> <span class="nb">false</span><span class="p">;</span>
                <span class="n">res</span> <span class="o">=</span> <span class="n">minus</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="o">*</span><span class="k">this</span><span class="p">);</span>
            <span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
                <span class="k">if</span> <span class="p">(</span><span class="n">isEqual</span><span class="p">(</span><span class="o">*</span><span class="k">this</span><span class="p">,</span> <span class="n">a</span><span class="p">))</span>
                    <span class="n">flag</span> <span class="o">=</span> <span class="nb">false</span><span class="p">;</span>
                <span class="k">else</span> <span class="n">flag</span> <span class="o">=</span> <span class="nb">true</span><span class="p">;</span>
                <span class="n">res</span> <span class="o">=</span> <span class="n">minus</span><span class="p">(</span><span class="o">*</span><span class="k">this</span><span class="p">,</span> <span class="n">a</span><span class="p">);</span>
            <span class="p">}</span>
        <span class="p">}</span> <span class="k">else</span> <span class="nf">if</span> <span class="p">(</span><span class="n">a</span><span class="p">.</span><span class="n">f</span> <span class="o">&amp;&amp;</span> <span class="o">!</span><span class="n">f</span><span class="p">)</span> <span class="p">{</span> <span class="c1">//左边为正，右边为负--左边-右边==左边+右边
</span><span class="c1"></span>            <span class="n">flag</span> <span class="o">=</span> <span class="nb">false</span><span class="p">;</span>
            <span class="n">res</span> <span class="o">=</span> <span class="n">add</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="o">*</span><span class="k">this</span><span class="p">);</span>
        <span class="p">}</span> <span class="k">else</span> <span class="nf">if</span> <span class="p">(</span><span class="o">!</span><span class="n">a</span><span class="p">.</span><span class="n">f</span> <span class="o">&amp;&amp;</span> <span class="n">f</span><span class="p">)</span> <span class="p">{</span> <span class="c1">//右边为正，左边为负--左边-右边==两边为负的加法
</span><span class="c1"></span>            <span class="n">flag</span> <span class="o">=</span> <span class="nb">true</span><span class="p">;</span>
            <span class="n">res</span> <span class="o">=</span> <span class="n">add</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="o">*</span><span class="k">this</span><span class="p">);</span>
        <span class="p">}</span> <span class="k">else</span> <span class="p">{</span> <span class="c1">//同时为正数--左边-右边==左边-右边(分类讨论正负
</span><span class="c1"></span>            <span class="k">if</span> <span class="p">(</span><span class="n">compare</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="o">*</span><span class="k">this</span><span class="p">))</span> <span class="p">{</span> <span class="c1">//右边&gt;左边,符号为负
</span><span class="c1"></span>                <span class="n">res</span> <span class="o">=</span> <span class="n">minus</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="o">*</span><span class="k">this</span><span class="p">);</span>
                <span class="n">flag</span> <span class="o">=</span> <span class="nb">true</span><span class="p">;</span>
            <span class="p">}</span> <span class="k">else</span> <span class="p">{</span> <span class="c1">//右边&lt;左边，符号为正
</span><span class="c1"></span>                <span class="n">res</span> <span class="o">=</span> <span class="n">minus</span><span class="p">(</span><span class="o">*</span><span class="k">this</span><span class="p">,</span> <span class="n">a</span><span class="p">);</span>
                <span class="n">flag</span> <span class="o">=</span> <span class="nb">false</span><span class="p">;</span>
            <span class="p">}</span>
        <span class="p">}</span>
        <span class="n">res</span><span class="p">.</span><span class="n">f</span> <span class="o">=</span> <span class="n">flag</span><span class="p">;</span>
        <span class="k">return</span> <span class="n">res</span><span class="p">;</span>
    <span class="p">}</span>

    <span class="kt">void</span> <span class="nf">print</span><span class="p">()</span> <span class="p">{</span>
        <span class="k">if</span> <span class="p">(</span><span class="n">f</span><span class="p">)</span>
            <span class="n">printf</span><span class="p">(</span><span class="s">&#34;-&#34;</span><span class="p">);</span>
        <span class="n">nums</span><span class="p">[</span><span class="n">length</span><span class="p">]</span> <span class="o">=</span> <span class="sc">&#39;\0&#39;</span><span class="p">;</span>
        <span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
        <span class="k">while</span> <span class="p">(</span><span class="n">nums</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">==</span> <span class="sc">&#39;0&#39;</span><span class="p">)</span><span class="n">i</span><span class="o">++</span><span class="p">;</span>
        <span class="n">printf</span><span class="p">(</span><span class="s">&#34;%s&#34;</span><span class="p">,</span> <span class="n">nums</span> <span class="o">+</span> <span class="n">i</span><span class="p">);</span>
    <span class="p">}</span>

    <span class="kt">void</span> <span class="nf">read</span><span class="p">()</span> <span class="p">{</span><span class="c1">//利用getchar()给对象赋上数据
</span><span class="c1"></span>        <span class="kt">char</span> <span class="n">c</span> <span class="o">=</span> <span class="n">getchar</span><span class="p">();</span>
        <span class="k">if</span> <span class="p">(</span><span class="n">c</span> <span class="o">==</span> <span class="sc">&#39;-&#39;</span><span class="p">)</span> <span class="p">{</span>
            <span class="n">f</span> <span class="o">=</span> <span class="nb">true</span><span class="p">;</span>
            <span class="n">c</span> <span class="o">=</span> <span class="n">getchar</span><span class="p">();</span>
        <span class="p">}</span>
        <span class="k">while</span> <span class="p">(</span><span class="n">c</span><span class="o">==</span><span class="sc">&#39;\n&#39;</span><span class="o">||</span><span class="n">c</span> <span class="o">==</span> <span class="sc">&#39;0&#39;</span><span class="o">||</span><span class="n">c</span> <span class="o">==</span> <span class="sc">&#39; &#39;</span><span class="p">)</span> <span class="n">c</span> <span class="o">=</span> <span class="n">getchar</span><span class="p">();</span><span class="c1">//将前导0消耗掉和空格
</span><span class="c1"></span>        <span class="k">while</span> <span class="p">(</span><span class="n">c</span> <span class="o">!=</span> <span class="sc">&#39;\n&#39;</span><span class="o">&amp;&amp;</span><span class="n">c</span> <span class="o">!=</span> <span class="sc">&#39; &#39;</span><span class="o">&amp;&amp;</span> <span class="n">c</span> <span class="o">!=</span> <span class="sc">&#39;\t&#39;</span><span class="p">)</span> <span class="p">{</span>
            <span class="n">push_back</span><span class="p">(</span><span class="n">c</span><span class="p">);</span><span class="c1">//不断的调用push_back即可
</span><span class="c1"></span>            <span class="n">c</span> <span class="o">=</span> <span class="n">getchar</span><span class="p">();</span>
        <span class="p">}</span>
    <span class="p">}</span>
<span class="p">};</span>

<span class="kt">int</span> <span class="nf">main</span><span class="p">()</span> <span class="p">{</span>
    <span class="k">using</span> <span class="k">namespace</span> <span class="n">std</span><span class="p">;</span>
    <span class="kt">int</span> <span class="n">n</span><span class="p">;</span>
    <span class="n">cin</span> <span class="o">&gt;&gt;</span> <span class="n">n</span><span class="p">;</span>
    <span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span> <span class="n">i</span> <span class="o">&lt;=</span> <span class="n">n</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span> <span class="p">{</span>
        <span class="kt">char</span> <span class="n">a</span><span class="p">[</span><span class="mi">100</span><span class="p">],</span> <span class="n">b</span><span class="p">[</span><span class="mi">100</span><span class="p">],</span> <span class="n">c</span><span class="p">[</span><span class="mi">100</span><span class="p">];</span>
        <span class="n">printf</span><span class="p">(</span><span class="s">&#34;Case #%d: &#34;</span><span class="p">,</span> <span class="n">i</span><span class="p">);</span>
        <span class="n">cin</span> <span class="o">&gt;&gt;</span> <span class="n">a</span> <span class="o">&gt;&gt;</span> <span class="n">b</span> <span class="o">&gt;&gt;</span> <span class="n">c</span><span class="p">;</span>
        <span class="n">BigInteger</span> <span class="n">a1</span><span class="p">(</span><span class="n">a</span><span class="p">),</span> <span class="n">b2</span><span class="p">(</span><span class="n">b</span><span class="p">),</span> <span class="n">c2</span><span class="p">(</span><span class="n">c</span><span class="p">);</span>
        <span class="n">BigInteger</span> <span class="n">t</span> <span class="o">=</span> <span class="n">c2</span> <span class="o">-</span> <span class="n">b2</span><span class="p">;</span>
        <span class="k">if</span> <span class="p">(</span><span class="n">t</span> <span class="o">&lt;</span> <span class="n">a1</span><span class="p">)</span>
            <span class="n">cout</span> <span class="o">&lt;&lt;</span> <span class="s">&#34;true</span><span class="se">\n</span><span class="s">&#34;</span><span class="p">;</span>
        <span class="k">else</span> <span class="n">cout</span> <span class="o">&lt;&lt;</span> <span class="s">&#34;false</span><span class="se">\n</span><span class="s">&#34;</span><span class="p">;</span>
    <span class="p">}</span>
    <span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>
</code></pre></div><p><strong>正确输出</strong>
<img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://img-blog.csdnimg.cn/790144900b9d4253972bab1ef6370986.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBAQ19ZQ0JYIFB5X1lZRFM=,size_20,color_FFFFFF,t_70,g_se,x_16"
        data-srcset="https://img-blog.csdnimg.cn/790144900b9d4253972bab1ef6370986.png?x-oss-process=image/watermark%2ctype_ZHJvaWRzYW5zZmFsbGJhY2s%2cshadow_50%2ctext_Q1NETiBAQ19ZQ0JYIFB5X1lZRFM=%2csize_20%2ccolor_FFFFFF%2ct_70%2cg_se%2cx_16, https://img-blog.csdnimg.cn/790144900b9d4253972bab1ef6370986.png?x-oss-process=image/watermark%2ctype_ZHJvaWRzYW5zZmFsbGJhY2s%2cshadow_50%2ctext_Q1NETiBAQ19ZQ0JYIFB5X1lZRFM=%2csize_20%2ccolor_FFFFFF%2ct_70%2cg_se%2cx_16 1.5x, https://img-blog.csdnimg.cn/790144900b9d4253972bab1ef6370986.png?x-oss-process=image/watermark%2ctype_ZHJvaWRzYW5zZmFsbGJhY2s%2cshadow_50%2ctext_Q1NETiBAQ19ZQ0JYIFB5X1lZRFM=%2csize_20%2ccolor_FFFFFF%2ct_70%2cg_se%2cx_16 2x"
        data-sizes="auto"
        alt="https://img-blog.csdnimg.cn/790144900b9d4253972bab1ef6370986.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBAQ19ZQ0JYIFB5X1lZRFM=,size_20,color_FFFFFF,t_70,g_se,x_16"
        title="https://img-blog.csdnimg.cn/790144900b9d4253972bab1ef6370986.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBAQ19ZQ0JYIFB5X1lZRFM=,size_20,color_FFFFFF,t_70,g_se,x_16" /></p>
<h2 id="总结">总结</h2>
<p>很多人，可能觉得做项目一定得是那种高大上，又或者是那种贪吃蛇小游戏、扫雷小游戏类型，实际上只要你有兴趣，任何一个东西都能成为你的练手项目，并且收获收获也许比你跟风去弄几个小游戏更大。</p>
<p>做这个小项目，我的收获是，对C++的语法更加的了解了，关于移动构造器、拷贝构造器、赋值重载这块弄得更清楚了，<strong>最大的收获在于强化了一个类的设计思路，这个是最重要的。</strong></p>
<p>多写一些类的实现，不仅有利于对算法和语言语法的理解，更大的收获在于对各个功能的设计思路，<strong>作为程序员，我们最需要的就是这样的逻辑思维，从接到需求开始，我们应该能迅速的抽象出各种实现方案，然后进行不断的优化，得出属于自己的代码！</strong></p>
</div><div class="post-footer" id="post-footer">
    <div class="post-info"><div class="post-info-tag"><span><a href="/tags/c&#43;&#43;%E7%B1%BB%E7%9A%84%E5%B0%81%E8%A3%85/">C&#43;&#43;类的封装</a>
                </span></div><div class="post-info-line"><div class="post-info-mod">
                <span>更新于 2022-01-20</span>
            </div><div class="post-info-mod"></div>
        </div><div class="post-info-share">
            <span><a href="javascript:void(0);" title="分享到 Twitter" data-sharer="twitter" data-url="https://acking-you.github.io/posts/%E5%A4%A7%E6%95%B4%E6%95%B0%E5%8A%A0%E5%87%8F/" data-title="大数加减类的实现(C&#43;&#43;实现)✨" data-hashtags="C&#43;&#43;类的封装"><i class="fab fa-twitter fa-fw"></i></a><a href="javascript:void(0);" title="分享到 Facebook" data-sharer="facebook" data-url="https://acking-you.github.io/posts/%E5%A4%A7%E6%95%B4%E6%95%B0%E5%8A%A0%E5%87%8F/" data-hashtag="C&#43;&#43;类的封装"><i class="fab fa-facebook-square fa-fw"></i></a><a href="javascript:void(0);" title="分享到 WhatsApp" data-sharer="whatsapp" data-url="https://acking-you.github.io/posts/%E5%A4%A7%E6%95%B4%E6%95%B0%E5%8A%A0%E5%87%8F/" data-title="大数加减类的实现(C&#43;&#43;实现)✨" data-web><i class="fab fa-whatsapp fa-fw"></i></a><a href="javascript:void(0);" title="分享到 Line" data-sharer="line" data-url="https://acking-you.github.io/posts/%E5%A4%A7%E6%95%B4%E6%95%B0%E5%8A%A0%E5%87%8F/" data-title="大数加减类的实现(C&#43;&#43;实现)✨"><i class="fab fa-line fa-fw"></i></a><a href="javascript:void(0);" title="分享到 微博" data-sharer="weibo" data-url="https://acking-you.github.io/posts/%E5%A4%A7%E6%95%B4%E6%95%B0%E5%8A%A0%E5%87%8F/" data-title="大数加减类的实现(C&#43;&#43;实现)✨" data-image="https://img-blog.csdnimg.cn/d01d5f8864d540fd9f68582d8f01d017.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBAQ19ZQ0JYIFB5X1lZRFM=,size_20,color_FFFFFF,t_70,g_se,x_16"><i class="fab fa-weibo fa-fw"></i></a><a href="javascript:void(0);" title="分享到 Myspace" data-sharer="myspace" data-url="https://acking-you.github.io/posts/%E5%A4%A7%E6%95%B4%E6%95%B0%E5%8A%A0%E5%87%8F/" data-title="大数加减类的实现(C&#43;&#43;实现)✨" data-description="”简单学习下基本的类封装“"><i data-svg-src="/lib/simple-icons/icons/myspace.min.svg"></i></a><a href="javascript:void(0);" title="分享到 Blogger" data-sharer="blogger" data-url="https://acking-you.github.io/posts/%E5%A4%A7%E6%95%B4%E6%95%B0%E5%8A%A0%E5%87%8F/" data-title="大数加减类的实现(C&#43;&#43;实现)✨" data-description="”简单学习下基本的类封装“"><i class="fab fa-blogger fa-fw"></i></a><a href="javascript:void(0);" title="分享到 Evernote" data-sharer="evernote" data-url="https://acking-you.github.io/posts/%E5%A4%A7%E6%95%B4%E6%95%B0%E5%8A%A0%E5%87%8F/" data-title="大数加减类的实现(C&#43;&#43;实现)✨"><i class="fab fa-evernote fa-fw"></i></a></span>
        </div></div><div class="post-nav"><a href="/posts/%E7%9F%A9%E9%98%B5%E5%BF%AB%E9%80%9F%E5%B9%82%E7%9A%84c&#43;&#43;%E5%B0%81%E8%A3%85/" class="prev" rel="prev" title="矩阵快速幂的C&#43;&#43;封装"><i class="fas fa-angle-left fa-fw"></i>Previous Post</a>
            <a href="/posts/socket%E5%9F%BA%E6%9C%AC%E6%93%8D%E4%BD%9Cc&#43;&#43;%E5%B0%81%E8%A3%85/" class="next" rel="next" title="Socket基本操作的C&#43;&#43;封装">Next Post<i class="fas fa-angle-right fa-fw"></i></a></div></div>
</div></article></div>
            </main>
            <footer class="footer"><div class="footer-container"><div class="footer-line">由 <a href="https://gohugo.io/" target="_blank" rel="noopener noreffer" title="Hugo 0.86.0">Hugo</a> 强力驱动 | 主题 - <a href="https://github.com/khusika/FeelIt" target="_blank" rel="noopener noreffer" title="FeelIt 1.0.1"><i class="fas fa-hand-holding-heart fa-fw"></i> FeelIt</a>
        </div><div class="footer-line" itemscope itemtype="http://schema.org/CreativeWork"><i class="far fa-copyright fa-fw"></i><span itemprop="copyrightYear">2023</span><span class="author" itemprop="copyrightHolder">&nbsp;<a href="/"></a></span></div>
</div>
</footer>
        </div>

        <div id="fixed-buttons"><a href="#" id="back-to-top" class="fixed-button" title="回到顶部">
                <i class="fas fa-chevron-up fa-fw"></i>
            </a></div><link rel="stylesheet" href="/lib/fontawesome-free/all.min.css"><link rel="stylesheet" href="/lib/animate/animate.min.css"><link rel="stylesheet" href="/lib/katex/katex.min.css"><link rel="stylesheet" href="/lib/katex/copy-tex.min.css"><script src="/lib/autocomplete/autocomplete.min.js"></script><script src="/lib/lunr/lunr.min.js"></script><script src="/lib/lunr/lunr.stemmer.support.min.js"></script><script src="/lib/lunr/lunr.zh.min.js"></script><script src="/lib/lazysizes/lazysizes.min.js"></script><script src="/lib/clipboard/clipboard.min.js"></script><script src="/lib/sharer/sharer.min.js"></script><script src="/lib/katex/katex.min.js"></script><script src="/lib/katex/auto-render.min.js"></script><script src="/lib/katex/copy-tex.min.js"></script><script src="/lib/katex/mhchem.min.js"></script><script>window.config={"code":{"copyTitle":"复制到剪贴板","maxShownLines":200},"comment":{},"math":{"delimiters":[{"display":true,"left":"$$","right":"$$"},{"display":true,"left":"\\[","right":"\\]"},{"display":false,"left":"$","right":"$"},{"display":false,"left":"\\(","right":"\\)"}],"strict":false},"search":{"highlightTag":"em","lunrIndexURL":"/index.json","lunrLanguageCode":"zh","lunrSegmentitURL":"/lib/lunr/lunr.segmentit.js","maxResultLength":100,"noResultsFound":"没有找到结果","snippetLength":50,"type":"lunr"}};</script><script src="/js/theme.min.js"></script></body></html>
